如何在没有来自C#中的控制台应用程序的数据的情况下向Web服务发送POST请求?

时间:2012-05-04 05:57:50

标签: c# post google-cloud-storage

我的Google云端存储项目要求使用空主体和一些请求标头发出POST请求,并获取Created(201)响应,其中包含上传ID以启动可恢复的上传。

我可以找到使用数据发送POST请求的引用,但是没有来自控制台应用程序的数据。

有没有人知道如何解决这个问题。

2 个答案:

答案 0 :(得分:3)

    using(var http = new WebClient())
    {
        http.Headers.Add("headername", "headervalue");
        var response = http.UploadData(address, new byte[0]);
    }

答案 1 :(得分:0)

Google云端存储在线文档包含描述可恢复上传协议(link)的部分。它包括以下启动可恢复上传的示例请求:

POST /music.mp3 HTTP/1.1
Host: example.commondatastorage.googleapis.com
Date: Fri, 01 Oct 2010 21:56:18 GMT
Content-Length: 0
Content-Type: audio/mpeg
x-goog-resumable: start
x-goog-api-version: 2
Authorization: OAuth 1/zVNpoQNsOSxZKqOZgckhpQ

您还可以查看boto source code,其中包含Google云端存储可恢复上传协议的Python实现(请参阅boto / gs / resumable_upload_handler.py)。