Note that there are some explanatory texts on larger screens.

plurals
  1. POwhat is equivalent of CURL in .NET
    primarykey
    data
    text
    <p>i need to connect to a URL and download data from it. the api documentation state that POST has to be made via CURL but i am using a .NET client.</p> <p>i wanted to know what is the CURL equivalent in .NET.</p> <p>tried the following but cannot get it to work</p> <pre><code> if (Request.QueryString["code"] != null) { // Response.Write(Request.QueryString["code"].ToString()); string url = "https://company.com/token/"; string data = "{client_id=id,client_secret=id,grant_type=authorization_code,code" + "=" + Request.QueryString["code"].ToString() + ",redirect_uri" + "=" + "http://localhost:10188/home.aspx" + ",scope=ancestry" + "}"; 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 response = null; string ret = null; try { response = myReq.GetResponse(); } catch (WebException ex) { if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.BadRequest) { Debug.WriteLine("Error 400 detected!!"); } response = (WebResponse)ex.Response; } finally { using (var streamReader = new StreamReader(response.GetResponseStream())) { ret = streamReader.ReadToEnd(); } } Response.Write(ret); } </code></pre> <p>the following code is now working</p> <pre><code>using (WebClient wc = new WebClient()) { System.Collections.Specialized.NameValueCollection reqparm = new System.Collections.Specialized.NameValueCollection(); reqparm.Add("client_id", mycon.client_id); reqparm.Add("client_secret", mycon.client_secret); reqparm.Add("grant_type", mycon.grant_type); reqparm.Add("code", mycon.code); reqparm.Add("redirect_uri", mycon.redirect_uri); reqparm.Add("scope", mycon.scope); byte[] responsebytes = wc.UploadValues(URL, "POST", reqparm); string responsebody = Encoding.UTF8.GetString(responsebytes); HttpContext.Current.Response.Write(responsebody); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload