Home >Backend Development >PHP Tutorial >http请求不成功

http请求不成功

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 14:13:561170browse

下面代码为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

0
test07
123456
123456
shengxiumei@fkhl.sh.cn





";

// soap 发送
// 第一次http请求
$ret_str = Socket_Connect_HTTP_Post("www.liveipc.com", "80", "/ipcam/soapservice", "", $soap_data); //数据包
// 第二次http请求
if($ret_str) {
$result = Socket_Connect_HTTP_Post("www.liveipc.com", "80", "/ipcam/soapservice", "", $soap_data, 200); 
}


回复讨论(解决方案)

错误代码有提示么?  这堆代码可以用编辑器框选起来,不然太乱。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:编码问题Next article:使用ecshop发送邮件出问题