0

好的,所以我到处看看这里和其他地方的大量帖子。我所拥有的是这样的 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# 中的内容,我无法使用我当前的代码进行复习。

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

谢谢杰森

4

1 回答 1

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 = "";

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

于 2013-01-02T11:34:00.950 回答