将包含数据的表单从控制器发布到外部URL的最佳方法是什么?
答案 0 :(得分:0)
您可以使用C#的HttpWebClient连接外部资源,然后发布数据。请参考此处:http://msdn.microsoft.com/en-us/library/debx8sh9.aspx。我希望之前google / bing会帮助你
答案 1 :(得分:0)
让我们在Example的帮助下理解。首先创建HttpClient
的对象,然后分配基地址let(https://stackoverflow.com/questions)和要发送的数据以及数据传输的数据类型。
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("https://stackoverflow.com/");//Assign Only Base Addresss
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
StringContent content = new StringContent(JsonConvert.SerializeObject(objDataYouWantTosend), Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("questions", content);
var data = response.Content.ReadAsAsync<"ClassNameInWhichresponseIsComming">();