2015-08-20 29 views
0

任何人都可以帮助我卷曲和.NET?我有这个服务器上的卷曲文档和一些主题的红色主要部分,但仍然不知道(如何格式化数据参数,头文件等)。 举例来说,我需要发送此卷曲要求: (gopay项目)帮助卷曲和C# - 基本(GoPay项目)

curl -v https://testgw.gopay.cz/api/oauth2/token \ 
-X "POST" \ 
-H "Accept: application/json" \ 
-H "Content-Type: application/x-www-form-urlencoded" \ 
-u "<Client ID>:<Client Secret>" \ 
-d "grant_type=client_credentials&scope=payment-create" 

后来这样的事情(大数据):

curl -v https://testgw.gopay.cz/api/payments/payment \ 
-X "POST" \ 
-H "Accept: application/json" \ 
-H "Content-Type: application/json" \ 
-H "Authorization: Bearer xzZnu3YnAHRk298EwdettFQMcbCcvmwTKKfhrJx2aGG8ZnFyBJhAvFW547WVSD7p" \ 
-d '{ 
     "payer": { 
        "default_payment_instrument":"BANK_ACCOUNT", 
        "default_swift":"FIAFZPP", 
        "contact":{"first_name":"Petr1", 
          "last_name":"Pan" 
          } 
       }, 
     "amount":"100", 
     "items":[{"name":"item01","amount":"500"}, 
       {"name":"item02","amount":"500"} 
       ], 
     "callback":{ 
        "return_url":"http://www.eshop.cz/return", 
        "notification_url":"http://www.eshop.cz/notify" 
       } 
}' 

回答

0

OK,工作的exaple(第一部分):

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://testgw.gopay.cz/api/oauth2/token"); 
     request.Method = "POST"; 
     request.Accept = "application/json";    
     string credentials = String.Format("{0}:{1}", "testid", "testecret"); 
     byte[] bytes = System.Text.Encoding.ASCII.GetBytes(credentials); 
     string base64 = Convert.ToBase64String(bytes); 
     string authorization = String.Concat("basic ", base64); 
     request.Headers.Add("Authorization", authorization); 
     request.ContentType = "application/x-www-form-urlencoded"; 

     using (var streamWriter = new StreamWriter(request.GetRequestStream())) 
     { 
      string data = "grant_type=client_credentials&scope=payment-create"; 

      streamWriter.Write(data); 
     } 

     WebResponse wr = request.GetResponse(); 
     Stream receiveStream = wr.GetResponseStream(); 
     StreamReader reader = new StreamReader(receiveStream, System.Text.Encoding.UTF8); 
     string content = reader.ReadToEnd(); 
     var json = "[" + content + "]"; // change this to array 
     var objects = JArray.Parse(json); // parse as array 
     foreach (JObject o in objects.Children<JObject>()) 
     { 
      foreach (JProperty p in o.Properties()) 
      { 
       string name = p.Name; 
       string value = p.Value.ToString(); 
      } 
     }