C# .NETRESTPUT CURL API

C# .NETRESTPUT CURL API,c#,.net,vb.net,rest,curl,C#,.net,Vb.net,Rest,Curl,好的,我有一个curl语句 curl -i -u user:pass -H "Accept: application/json" -X POST -d "type=menu&title=HelloWorld" http://127.0.0.1:8000/api/pages/ 但是我不能让它在.net中工作 我试过了 private void button1_Click(object sender, EventArgs e) { try {

好的,我有一个curl语句

curl -i -u user:pass -H "Accept: application/json" -X POST -d "type=menu&title=HelloWorld" http://127.0.0.1:8000/api/pages/
但是我不能让它在.net中工作

我试过了

   private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            var client = new RestClient("http://127.0.0.1:8000/api/pages/");
            client.Authenticator = new HttpBasicAuthenticator("user", "pass");

            var request = new RestRequest(Method.POST);
            request.AddHeader("Accept", "application/json");


            // add parameters for all properties on an object
            request.AddParameter("type", "menu");
            request.AddParameter("title", "HelloWorld");


            // execute the request
            RestResponse response = client.Execute(request);
            var content = response.Content; // raw content as string
            richTextBox1.Text = content.ToString();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
和straight.net

 Private Sub ButtonPost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonPost.Click

    address = New Uri("http://127.0.0.1:8000/api/pages")

    ' Create the web request  
    request = DirectCast(WebRequest.Create(address), HttpWebRequest)

    ' Set type to POST  
    request.Method = "POST"
    request.ContentType = "Accept: application/json"

    ' Add authentication to request  
    request.Credentials = New NetworkCredential("user", "pass")

    Dim str As String = "type=men&title=HelloWorld"
    ' Create a byte array of the data we want to send  
    byteData = UTF8Encoding.UTF8.GetBytes(str)

    ' Set the content length in the request headers  
    request.ContentLength = byteData.Length

    ' Write data  
    Try
        postStream = request.GetRequestStream()
        postStream.Write(byteData, 0, byteData.Length)
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    Finally
        If Not postStream Is Nothing Then postStream.Close()
    End Try

    Try
        ' Get response  
        response = DirectCast(request.GetResponse(), HttpWebResponse)

        ' Get the response stream into a reader  
        reader = New StreamReader(response.GetResponseStream())

        ' Console application output  
        RichTextBox1.Text = reader.ReadToEnd()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    Finally
        If Not response Is Nothing Then response.Close()
    End Try

End Sub

当你“无法让它工作”时,有助于对行为进行定义。我尝试了很多不同的方法,在RestSharp中,它通常表示禁止(有时是不好的要求)而且在直vb.net通常是说内部服务器错误500你可以发电子邮件给我在pmtolk gmail,我会给你的用户和通过,如果你想测试的东西!!!令人惊叹的无需更正的所有大写问题标题。