Note that there are some explanatory texts on larger screens.

plurals
  1. POC#: POST request with BASIC authentication mixes QUERY_STRING and REQUEST_METHOD in PHP?
    primarykey
    data
    text
    <p>I have a problem with sending a POST request from C# to a PHP script on my Apache (Windows) server. Everything works fine, unless I instruct Apache to require a valid user using BASIC authentication through a <code>.htaccess</code> file.</p> <p>But let's put things in order. I'm using the following code to send a list of key/value pairs to my PHP script using HTTP-POST:</p> <pre><code>NameValueCollection nameValues = new NameValueCollection(); nameValues["operation"] = ...; nameValues["order"] = ...; nameValues["status"] = ...; nameValues["comment"] = ...; nameValues["user"] = ...; WebClient webClient = new WebClient(); try { CredentialCache credentialCache = new CredentialCache(); credentialCache.Add(new Uri(PERFORM_URL), "Basic", new NetworkCredential(PERFORM_USER, PERFORM_PASSWORD)); webClient.Credentials = credentialCache; byte[] response = webClient.UploadValues(PERFORM_URL, "POST", nameValues); string responseString = Encoding.ASCII.GetString(response); } finally { webClient.Dispose(); } </code></pre> <p>The PHP script on the server looks like this:</p> <pre><code>&lt;?php print_r($_SERVER); ?&gt; </code></pre> <p>So I just output some header information here. I turn off basic authentication in my <code>htaccess</code> file, everything's fine. When I turn it on, however, I get the following output:</p> <pre><code>Array ( ... [REMOTE_USER] =&gt; **** [AUTH_TYPE] =&gt; Basic [GATEWAY_INTERFACE] =&gt; CGI/1.1 [SERVER_PROTOCOL] =&gt; HTTP/1.1 [REQUEST_METHOD] =&gt; operation=updatestatus&amp;order=185&amp;status=17&amp;comment=Test&amp;user=somenamePOST [QUERY_STRING] =&gt; ... [PHP_AUTH_USER] =&gt; **** [PHP_AUTH_PW] =&gt; **** [REQUEST_TIME] =&gt; 1286889387 [argv] =&gt; Array ( ) [argc] =&gt; 0 ) </code></pre> <p>Where, the <code>REQUEST_METHOD</code> contains all the parameters + the appended <code>POST</code>. This is wrong. What can I do about it? I've also read and tried solutions, where people used <code>HttpWebRequest</code> using the <code>PreAuthenticate</code> property - but that didn't work for me either.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload