0

要更新的页面的 URL(如果单击它,链接将不起作用,它只是一个示例):https ://test-services.zzz111.org/yyy-9/center/api/rest/v1/pols/ZYPK

我假设我需要在这个 URL 上做一个 POST。

以下是请求示例:

<PolChangeSet schemaVersion="2.1" username="ZZ@yyy999.com" description="Adding a note">
    <Attachment name="pic.jpg" contentType="image/jpeg">
        <Description/>
        <Location>https://services.zzz111.com/yyy-9/center/api/sdo/rest/v1/buckets/attachments/objects/6BD0C43B-4608-0EDE-F6DA-919097EFCABF.jpg</Location>
    </Attachment>
</PolChangeSet>

我将如何将此 HTTP POST 请求发送到 URL?

4

2 回答 2

1

如果需要后台发帖,可以参考这个http://www.hanselman.com/blog/HTTPPOSTsAndHTTPGETsWithWebClientAndCAndFakingAPostBack.aspx

并通过 xml 将 URI 和参数作为字符串传递

我编辑了原始源并将 contentType 添加为附加参数。XML 类型是"application/xml"

public static string HttpPost(string URI, string Parameters, string contentType) 
{
   System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
   req.Proxy = new System.Net.WebProxy(ProxyString, true);
   //Add these, as we're doing a POST
   req.ContentType = contentType;
   req.Method = "POST";
   //We need to count how many bytes we're sending. Post'ed Faked Forms should be name=value&
   byte [] bytes = System.Text.Encoding.ASCII.GetBytes(Parameters);
   req.ContentLength = bytes.Length;
   System.IO.Stream os = req.GetRequestStream ();
   os.Write (bytes, 0, bytes.Length); //Push it out there
   os.Close ();
   System.Net.WebResponse resp = req.GetResponse();
   if (resp== null) return null;
   System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
   return sr.ReadToEnd().Trim();
}
于 2012-08-10T01:20:11.840 回答
0

您可以使用 jquery 来执行此操作。

$.post(
    "action.php", 
    {"xmlString":xmlString}, 
    function (response){
        alert(response);
    }
);

然后您可以在服务器端将 xml 字符串解析为您的对象。这里有一些关于 jquery post http://api.jquery.com/jQuery.post/的例子

或者你可以看看这个答案,它是相似的:how to pass xml as parameter using POST method and using jquery ajax

于 2012-08-10T00:54:03.327 回答