2013-05-04 46 views
2

我是新來的webservice,我試圖發送JSON數據到我的WP7應用程序在VS2010中創建的.php webservice。我已使用UploadStringAsync方法,但此方法不適用於GET方法。它在使用GET方法時拋出異常。請幫忙。下面如何發送數據到php webservice使用GET方法在JSON格式在C#

是我的C#代碼

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() + " }"); 

下面是我的web

<?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; 
?> 

回答

0

使用GET方法,u'v使用DownloadStringAsync代替。

相關問題