HTTP post在wp7上不工作,名称字段没有发送过来

本文关键字:字段 wp7 post 工作 HTTP | 更新日期: 2023-09-27 17:50:33

我看了看这里和其他地方的大量帖子。我有一个这样的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);

当我得到响应时它是error

注意:未定义的索引:日历在htdocs'test'testinput.php的第11行数组注意:试图在htdocs'test'testinput.php第30行获得非对象的属性

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

现在如果我使用一个标准的html post,像这样:

<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#中是我无法用我当前的代码来处理的。

任何帮助将不胜感激。我希望这不是很复杂。我想我只是错过了一些东西,但我没有找到任何通过阅读类描述。

谢谢杰森

HTTP post在wp7上不工作,名称字段没有发送过来

所以我发现这里的工作是我必须在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 = "";

这样我就可以从手机中获得值,并根据需要将它们添加到数据库中。