c# - 如何在 C# 中使用 JSON 格式的 GET 方法将数据发送到 php webservice

标签 c# php

我是网络服务的新手,我正在尝试从我在 VS2010 中创建的 WP7 应用程序将 JSON 数据发送到 .php 网络服务。我使用了 UploadStringAsync 方法,但此方法不适用于 GET 方法。使用 GET 方法时抛出异常。请帮忙。

下面是我的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() + " }");

下面是我的网络服务

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

关于c# - 如何在 C# 中使用 JSON 格式的 GET 方法将数据发送到 php webservice,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16372623/

相关文章:

c# - 无法加载文件或程序集 'Microsoft.Extensions.Logging.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'

c# - 是否可以提供多个约束作为类型参数?

php - 列 取决于其他列

javascript - 使用数组 php 参数从 php 调用 javascript 函数

php - Laravel 5.1 + PHPunit - API 测试总是返回无效参数错误

c# - 尝试在 Unity 中实现 Jacobian IK 示例概述

c# - 在 .NET 3.5 上实现 Pub/Sub 或 SignalR 功能?

c# - 从方法返回数据读取器

php - 更新我刚刚创建的记录

php - 通过带有客户端身份验证的 SSL 进行 curl