Issue FORM POST Request From PHP using HTTP Basic Authentication

后端 未结 2 584
被撕碎了的回忆
被撕碎了的回忆 2021-01-04 14:07

I hope this is a relatively straight forward thing to do, and that my google skills have simply failed me on this occasion. I have a BASIC authentication protected resource

2条回答
  •  星月不相逢
    2021-01-04 14:37

    Using:

    $header = "POST /someendpoint HTTP/1.1\r\n".
            "Host:example.com\n".
            "Content-Type: application/x-www-form-urlencoded\r\n".
            "User-Agent: PHP-Code\r\n".
            "Content-Length: " . strlen($req) . "\r\n".
            "Authorization: Basic ".base64_encode($username.':'.$password)."\r\n".
            "Connection: close\r\n\r\n";
    

    Should work - are you sure it is a Basic authentication system? It may be worth watching the raw header data using something like CharlesProxy to ensure it is an authentication (and you'll be then able to copy the authorization string as well!).

提交回复
热议问题