.NET中的卷曲请求

时间:2014-10-20 13:34:43

标签: c# curl

我在.NET中发出以下CURL请求,如下所示。

卷曲:

curl -XPOST https://api.domain.com/v1/OTP/1234-5678-9012/ss123.123 \
-d "private=aaaa-bbbb"

.NET:

string url = "https://api.domain.com/v1/OTP/1234-5678-9012/ss123.123";
string data = "{\"private\"=\"aaaa-bbbb\"}";

WebRequest myReq = WebRequest.Create(url);
myReq.Method = "POST";
myReq.ContentLength = data.Length;
myReq.ContentType = "application/json; charset=UTF-8";

UTF8Encoding enc = new UTF8Encoding();

using (Stream ds = myReq.GetRequestStream())
{
    ds.Write(enc.GetBytes(data), 0, data.Length);
}

WebResponse wr = myReq.GetResponse();
Stream receiveStream = wr.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
string content = reader.ReadToEnd();

但我收到方法不支持错误,我缺少什么?

0 个答案:

没有答案