转换卷曲命令.NET [英] Converting a cURL command to .NET

查看:177
本文介绍了转换卷曲命令.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜有,我想转换到VB.NET或C#以下cURL命令。

Hi have the following cURL command that I would like to convert to VB.NET or C#.

curl https://api.box.com/2.0/users \-H "Authorization: Bearer ACCESS_TOKEN" \ -d '{"login": "eddard@company.com", "name": "Ned Stark"}' \ -X POST

我试着在VB.NET如下:

I've tried the following in VB.NET:

Dim url As String = "https://api.box.com/2.0/users"
Dim wrq = CType(Net.WebRequest.Create(url), HttpWebRequest)
Dim postString As String = "login=eddard@company.com&name=Ned Stark"

wrq.Headers.Add("Authorization: Bearer " & o2ses.AccessToken)
wrq.Method = "POST"
wrq.ContentType = "application/x-www-form-urlencoded"
wrq.ContentLength = postString.Length

Dim wrqWriter As New StreamWriter(wrq.GetRequestStream())
wrqWriter.Write(postString)
wrqWriter.Close()

Dim responseReader As New StreamReader(wrq.GetResponse().GetResponseStream())
Dim responseData As String = responseReader.ReadToEnd()

我是一个福利局卷曲,并在.NET中使用HttpWebRequest的,但转换卷曲命令之前(感谢这个网站:))到.NET,但没有与他们-d选项,所以我有点的丢失。它使返回错误400(错误的请求)线下执行时。

I am a newb to cURL and to using HttpWebRequest in .NET, but have converted cURL commands to .NET before (thanks to this site :)), but none with the -d option in them, so I'm kind of lost. It keeps returning error 400 (bad request) when the line below is executed.

Dim responseReader As New StreamReader(wrq.GetResponse().GetResponseStream())

我觉得它做什么样的数据我送(即它没有得到适当的登陆,它需要'名'参数)。

I think it has to do with what data I am sending (i.e. it's not getting the proper 'login' and 'name' parameters it needs).

任何帮助是AP preciated。我可以尝试在需要时提供更多的信息。如前所述,我是一个福利局到这一点,所以我会尽我所能。

Any help is appreciated. I can try to provide more information if needed. As mentioned, I'm a newb to this, so I'll try my best.

谢谢!

推荐答案

我不知道vb.net,但我认为授权头应该是这样的:

I do not know vb.net but I think that the authorization header should look like this:

wrq.Headers.Add(HttpRequestHeader.Authorization, "Bearer " & o2ses.AccessToken);

这篇关于转换卷曲命令.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆