简体   繁体   中英

how to send data to php webservice using GET method in JSON Format in C#

I am new to webservice, and I am trying to send JSON data to .php webservice from my WP7 application created in VS2010. I have used the UploadStringAsync method, but this method is not working with the GET method. It is throwing exception while using the GET Method. Please help.

below is my c# code

WebClient postWithParamsClient = new WebClient();

postWithParamsClient.Headers["Content-type"] = "application/json";
postWithParamsClient.UploadStringCompleted += new UploadStringCompletedEventHandler(postWithParamsClient_UploadStringCompleted);

postWithParamsClient.UploadStringAsync(url, "POST", "{ \"latitude\": " + textBox2.Text.ToString() + ", \"longitude\": " + textBox3.Text.ToString() + " }");

below is my webservice

<?php
/*XML FORMAT
<gpstrack>
    <latitude>30°N</latitude>
    <longitude>38°N</longitude>
    <mobtime>mobiletime</mobtime>
</gpstrack>
XML FORMAT*/

$xml = file_get_contents('php://input');
$finalArray = json_decode(json_encode((array) simplexml_load_string($xml)),1);
//$finalArray=array('latitude'=>'12.1','longitude'=>'3.2','mobtime'=>'325695142');

$newfb = new TABLE($db,"gpslog","track_id");
$newfb -> latitude              = $finalArray['latitude'];
$newfb -> longitude             = $finalArray['longitude'];
$newfb -> mobtime               = strtotime($finalArray['mobtime']);

$newfb -> insert(); 
print "success";

exit;
?>

要使用GET方法,请改用DownloadStringAsync

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM