HTTP request unsuccessful workaround

Source: Internet
Author: User
HTTP request not successful
The following code is the HTTP request code.
Second request not successful, please help to see where the wrong?

Normal process: Send HTTP request, 401 response, send the HTTP request with authentication again, return 200. End.
Note: The account password in the code is the default, so there is no extraction of the first return of the data in the account, password. The default data is used for the account password in the second request.

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
  • /soap-env:body>

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.