我在.NET中创建HTTP post请求时遇到问题。当我在ruby中执行此请求时,它确实有效。
在.NET中执行请求时出现以下错误:
<h1>FOXISAPI call failed</h1><p><b>Progid is:</b> carejobs.carejobs
<p><b>Method is:</b> importvacature/
<p><b>Parameters are:</b>
<p><b> parameters are:</b> vacature.deelnemernr=478
</b><p><b>GetIDsOfNames failed with err code 80020006: Unknown name.
</b>
有谁知道如何解决这个问题?
红宝石:
require 'net/http' url = URI.parse('http://www.carejobs.be/scripts/foxisapi.dll/carejobs.carejobs.importvacature') post_args = { 'vacature.deelnemernr' => '478', } resp, data = Net::HTTP.post_form(url, post_args) print resp print data
C#:
Uri address = new Uri(url); // Create the web request HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest; // Set type to POST request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; // Create the data we want to send StringBuilder data = new StringBuilder(); data.Append("vacature.deelnemernr=" + HttpUtility.UrlEncode("478")); // Create a byte array of the data we want to send byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString()); // Set the content length in the request headers request.ContentLength = byteData.Length; // Write data using (Stream postStream = request.GetRequestStream()) { postStream.Write(byteData, 0, byteData.Length); } // Get response using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { // Get the response stream StreamReader reader = new StreamReader(response.GetResponseStream()); // Console application output result = reader.ReadToEnd(); } return result;
答案 0 :(得分:0)
答案 1 :(得分:-1)