目前我通过curl命令将信息传递给Web API,如下所示:
val cache = igniteContext.fromCache("partitioned")
val result = cache.filter(_._2.contains("Ignite")).collect()
这将返回API的另一个URL,在那里发布所有信息:
http://example.com/xyz#newjobapi:id=19
我试图通过C #Windows表单复制此过程,用户将在其中输入所需信息,一旦提交,他们应该获得返回的URL。
我已经为用户创建了输入此信息的界面。但我不知道如何将此信息发布到Web API并获取生成的URL
是否有可用于通过Windows Form复制上述curl进程的库?
答案 0 :(得分:1)
HttpWebRequest webRequest;
string requestParams = ""; //format information you need to pass into that string ('info={ "EmployeeID": [ "1234567", "7654321" ], "Salary": true, "BonusPercentage": 10}');
webRequest = (HttpWebRequest)WebRequest.Create("http://example.com/xyz/php/api/createjob.php");
webRequest.Method = "POST";
webRequest.ContentType = "application/json";
byte[] byteArray = Encoding.UTF8.GetBytes(requestParams);
webRequest.ContentLength = byteArray.Length;
using (Stream requestStream = webRequest.GetRequestStream())
{
requestStream.Write(byteArray, 0, byteArray.Length);
}
// Get the response.
using (WebResponse response = webRequest.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
StreamReader rdr = new StreamReader(responseStream, Encoding.UTF8);
string Json = rdr.ReadToEnd(); // response from server
}
}