i can't set params to my web service this is my code in php :
$myValue = $_POST['myValue'];
and this is my C# Code :
void POST(string url, string jsonContent)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
Byte[] byteArray = encoding.GetBytes("myValue=" + jsonContent);
request.ContentLength = byteArray.Length;
request.ContentType = @"application/json";
using (Stream dataStream = request.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
}
long length = 0;
try
{
//request.GetResponse();
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
length = response.ContentLength;
using (Stream responseStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
string WSReturned = reader.ReadToEnd();
}
}
}
catch (WebException ex)
{
//Nothing...
}
}
i tested "&myValue=" and return null again
This is my PHP Code :
<?php
if (isset($_POST['NewArray'])) {
$NewArray = $_POST['NewArray'];
} else {
$NewArray = "Not";
}
echo $NewArray;?>
If you append &myValue=Something
to your query string you don't use $_POST
to get the value but use $_GET
instead.
Now coming to your code it seems okay to me, maybe the error is an another point of your application.
I suggest you to check if there's a value in $_POST
with isset, and then try to debug it.
If you get an exception then please post the logs, hope it helps :)