http帖子没有在wp7上工作,名字字段没有发送过来

时间:2013-01-02 00:30:15

标签: c# php windows-phone-7

好的,所以我在这里看看大量的帖子和其他地方。我有一个像这样的PHP脚本。

<?php


//gets the post from the phone app
$calendar = $_POST[ 'calendar' ];

//converts the post into a string for manipulation
$xml = simplexml_load_string($calendar); 

rest of code omitted

然后在C#中我有这个

string Event_xml;
Event_xml = "<?xml version='1.0' encoding='ISO-8859-1' ?><calendar><event><event_id></event_id><title>"+ local_title +"</title><venue_id>1</venue_id><contact_id>1</contact_id><description>"+ local_description +"</description><category_id>1</category_id><user_id>" + local_ID + "</user_id><group_id>1</group_id><status_id>1</status_id><date>" + local_startDate + "</date><starttime>" + local_startTime + "</starttime><endDate>" + local_endDate + "</endDate><endtime>" + local_endTime + "</endtime></event></calendar>";

WebClient wc = new WebClient();
var URI = new Uri("http://jasonsftp.no-ip.info/test/EventInput.php");
        wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";
        wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);

        wc.UploadStringAsync(URI, "POST", Event_xml);

当我收到回复时,这是错误

注意:未定义的索引:第11行的htdocs \ test \ testinput.php中的日历 排列 注意:尝试在第30行的htdocs \ test \ testinput.php中获取非对象的属性

警告:第30行的htdocs \ test \ testinput.php中为foreach()提供的参数无效

现在如果我使用这样的标准html帖子:

<form action="http://jasonsftp.no-ip.info/test/testinput.php?" method="post">
      <input type="text" name="calendar" value="mydata" />
      <input type="submit" />
    </form>

它运作得很好。 所以name =“calendar”就是C#中我不能用我当前的代码来完成的。

任何帮助将不胜感激。我希望这不是很复杂。我想我只是遗漏了一些东西,但在阅读课程描述时我没有找到任何东西。

感谢 杰森

1 个答案:

答案 0 :(得分:0)

所以我发现这里有用的是我必须在c#

中做的事情
WebClient wc = new WebClient();


        string sendData = "";
        var URI = new Uri("http://jasonsftp.no-ip.info/test/testinput.php");
        wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";


        sendData += "&title="+local_title;
        sendData += "&event_id=";
        sendData += "&venue_id=1";
        sendData += "&contact_id=1";
        sendData += "&description=" + local_description;
        sendData += "&category_id=1";
        sendData += "&user_id=" + local_ID;
        sendData += "&group_id=1";
        sendData += "&status_id=1";
        sendData += "&date=" + local_startDate;
        sendData += "&start_time=" + local_startTime;
        sendData += "&end_date=" + local_endDate;
        sendData += "&end_time=" + local_endTime;

        wc.Headers[HttpRequestHeader.ContentLength] = sendData.Length.ToString();
        wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);

        wc.UploadStringAsync(URI, "POST", sendData);

对于php来说,这就是我做的工作

<?php

$title = $_POST['title'];
$event_id = $_POST['event_id'];
$venue_id = $_POST['venue_id'];
$contact_id = $_POST['contact_id'];
$description = $_POST['description'];
$category_id = $_POST['category_id'];
$user_id = $_POST['user_id'];
$group_id = $_POST['group_id'];
$status_id = $_POST['status_id'];
$date = $_POST['date'];
$start_time = $_POST['start_time'];
$end_date = $_POST['end_date'];
$end_time = $_POST['end_time'];
$latitude = "";
$longitude = "";

我可以从手机获取值并根据需要将它们添加到数据库中。