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