当前位置:
开发笔记 >
Android > 正文
http请求不成功解决办法
作者:书友16941424_529 | 来源:互联网 | 2014-03-27 18:17
http请求不成功下面代码为HTTP请求代码。第二次请求不成功,请帮忙看一下错在哪里?正常流程:发送http请求,401响应,再次发送带验证的http请求,返回200。结束。注:代码中的账号密码都是默认的,所以没有提取第一次返回的数据中的账号,密
http请求不成功
下面代码为HTTP请求代码。
第二次请求不成功,请帮忙看一下错在哪里?
正常流程:发送http请求,401响应,再次发送带验证的http请求,返回200。结束。
注:代码中的账号密码都是默认的,所以没有提取第一次返回的数据中的账号,密码。第二次请求中的账号密码都用默认数据。
function Socket_Connect_HTTP_Post($server, $port, $dir, $file, $data, $type = '') {
$send_url = str_replace("%2F", "/", rawurlencode(rawurldecode(urldecode($dir . $file))));
$method = "POST";
$http_header_array["ALL"][] = "Accept: */*";
$http_header_array["ALL"][] = "Referer: http://".$server."/";
$http_header_array["ALL"][] = "Accept-Language: en-us,zh-cn";
$http_header_array["ALL"][] = "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$http_header_array["ALL"][] = "Connection: Keep-Alive";
$http_header_array["ALL"][] = "Host: ".$server;
$http_header_array["ALL"][] = "urn:po-processor";
if(!empty($type)) {
$http_header_array["ALL"][] = "Authorization: Digest realm=\"www.fkhl.sh.cn\", username=\"FHL3301009\", nOnce=\"MTM3MTc5Njg3Mjg3NjpkN2RmYmE4ZDFmMzNiZGQ0ZTAxMDJjMTNjZjI3MDQ2ZQ==\", uri=\"/ipcam/soapservice\", nc=00000001, cnOnce=\"51c3f331ca5600006784\", respOnse=\"dc0f6160daa71c7e86416e0f1cb63d59\", qop=\"auth\"";
}
$http_header_array["ALL"][] = "SOAPAction:http://www.liveipc.com/UserService/UserOperation";
$http_header_array["POST"][] = "Cache-Control: no-cache";
$http_header_array["POST"][] = "Content-Type: text/xml";
$http_header_array["POST"][] = "Content-Length: ".strlen($data);
if (is_array($http_header_array["ALL"])) {
$http_header_str_all = implode("\r\n", $http_header_array["ALL"]);
}
if (is_array($http_header_array[$method])) {
$http_header_str_all .= "\r\n".implode("\r\n", $http_header_array[$method]);
}
$send_all = "POST ".$send_url." HTTP/1.1\r\n".$http_header_str_all."\r\n\r\n";
$send_all .= $data."\r\n\r\n";
$fp_send = fsockopen($server, $port, $errno, $errstr ,30);
if ($fp_send)
{
$can_rcv = 0;
fputs($fp_send, $send_all);
stream_set_timeout($fp_send, 120);
while(!feof($fp_send))
{
$content_t = fgets($fp_send, 1024);
if ((trim($content_t) == "") && !$can_rcv)
{
$can_rcv = 1;
$content_t = fgets($fp_send, 1024);
}
if ($can_rcv == 1 and strlen($content_t)>5)
{
$reply_str .= $content_t;
}
}
$stream_status = stream_get_meta_data($fp_send);
fclose($fp_send);
if ($stream_status[timed_out])
{
$reply_str = "";
}
}
return $reply_str;
}
$soap_data = "
1.0.0
GBK
UserRegistration
c7c92fc2882f41f92249fac90aad7bb6
推荐阅读
-
MyBatis模糊查询和多条件查询一、ISmbmsUserDao层根据姓名模糊查询publicListgetUser();多条件查询publicList ...
[详细]
蜡笔小新 2024-09-30 13:26:10
-
软件自动化测试的学习步骤软件测试交流群关注软件测试技术公众号获取阅读目录软件自动化测试的学习步骤自动化测试的本质自动化测试学习的误区自动化测试的职位自动化测试分类Web自动化 ...
[详细]
蜡笔小新 2024-09-30 01:54:19
-
-
之前一直使用的是nodev2.2.0版本,挺说新版本的node解决了npm安装插件产生文件夹结构过深的问题,所以就想更新试试;上网一看才发现,尼玛的node已经到了6.+版本了,好 ...
[详细]
蜡笔小新 2024-09-29 12:25:49
-
thecontainercontainsthemos ...
[详细]
蜡笔小新 2024-09-30 18:33:10
-
*tomcat1192.168.10.153*tomcat2192.168.10.154Tomcat工作模式必须为Nio模式。##添加如下内容,注意更换address ...
[详细]
蜡笔小新 2024-09-30 14:52:41
-
篇首语:本文由编程笔记#小编为大家整理,主要介绍了sql盲注之报错注入(附自动化脚本)相关的知识,希望对你有一定的参考价值。 ...
[详细]
蜡笔小新 2024-09-30 12:32:17
-
–声明变量DECLAREBuCodeASvarchar(max)–声明游标DECLAREC_EmployeesCURSORFAST_FORWARDFORSELECTBUCodeFR ...
[详细]
蜡笔小新 2024-09-30 10:08:21
-
蜡笔小新 2024-09-29 19:47:31
-
一、基本Tag1.Tag定义了Item实例,有三个基本的属性来定义一个item实例,大小写敏感。id-每个Item实例的唯一标识type ...
[详细]
蜡笔小新 2024-09-29 17:57:33
-
webservice框架有很多,比如axis、axis2、cxf、xFire等等,做服务端和做客户端都可行,个人感觉使用这些框架的好处是减少了对于接口信息的解析,最主要的是减少了对于传递于网络中XML ...
[详细]
蜡笔小新 2024-09-29 16:46:39
-
对Android的启动模式不是很了解,这里记录下简单的理解内容以便日后查看。 Androi的四种启动模式分别为:standard,singleTop,singleTask,sing ...
[详细]
蜡笔小新 2024-09-29 16:20:47
-
Flex中使用filter过滤数据 ...
[详细]
蜡笔小新 2024-09-29 14:51:58
-
这篇文章主要介绍了intellijidea修改maven配置时总是恢复默认配置的解决方法idea版本(2020.2.x),本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考 ...
[详细]
蜡笔小新 2024-09-29 14:51:40
-
一、使用ContentProvider(内容提供者)共享数据ContentProvider在android中的作用是对外共享数据,也就是说 ...
[详细]
蜡笔小新 2024-09-29 13:49:00
-
一、ScrapyScrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架。可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中。。用 ...
[详细]
蜡笔小新 2024-09-29 13:04:13
-
书友16941424_529
这个家伙很懒,什么也没留下!