WebClient.UploadValues PHP Script not Retrieving Variables Values Fiddler Shows Variables defined and Values

31 views Asked by At

I have upload my variables via WebClient.UploadValues and that appears to have worked according to Fiddler Request Headers as shown on the WebForms tab. I can see both my variables in the Body section just below the query string section above it. My variables are UploadFilename & UploadFilepath and both variable are showing their correct values. The code below show the WebClient code I use to do this.

 public static string PostValuesToURL(string url, string param1, string param2)
    {
        using (WebClient wc = new WebClient())
        {
            wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            NameValueCollection formData = new NameValueCollection();
            formData["UploadFilename"]= param1;
            formData["UploadFilepath"]= param2;
            byte[] response = wc.UploadValues(url, "POST", formData);
            string responseString = System.Text.Encoding.UTF8.GetString(response);
            wc.Dispose();
            return responseString;
        }
    }

The way I use the above code is a call to PostValuestoURL as follows. I am developing on my localhost. By specifying localhost or 127.0.0.1 did not work for me in the WebClient URL, I had to use my machine name in the URL. I had success with that.

PostValuesToURL("http://your machine name/somesite/index.php", filename, filePath);

Observing again in Fiddler I could see the variables defined and their values in the WebForms tab of Request Header. They had uploaded correctly. Now the php code to retrieve the variables is as below.

if (isset($_POST['UploadFilename'])){
    $UploadFilename=filter_var($_POST["UploadFilename"],FILTER_SANITIZE_STRING); //Sanatize the input
}else{
    
    //$body = file_get_contents('php//input');
    //echo $body;
    $UploadFilename="Variable Not Set...";
}

if (isset($_POST['UploadFilepath'])){
    $UploadFilepath=filter_var($_POST["UploadFilepath"],FILTER_SANITIZE_STRING); //Sanatize the input
}else{
    
    $UploadFilepath="Variable Not Set...";
}

Again observing in Fiddler this time the request body and looking at either the SyntaxView or the Raw tabs, I could see my values as they should be in the index.php script. Now Oddly even though the values are shown in Fiddler, the isset fails in my index.php script and both variables are to "Variable not Set..." the else side of the IF statement for both variables. I can't explain the activity in Fiddler and yes the index.php says the variables are not set. Ultimately I am trying to retrieve the two variables values via php UploadFilename & Uploadfileapth and inject them into two Javascript variables as shown below.

var UploadFilename = "<?php echo $UploadFilename ?>";
var UploadFilepath = "<?php echo $UploadFilepath ?>";

The values saved to both JavaScript is "Variable not set..."

Can anybody explain this? I am reasonably new to Fiddler. Maybe Fiddler is playing tricks with me. Any help much appreciated.

0

There are 0 answers