.NET中的HTTP POST不起作用

我在使用.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;

你不需要吗? 之后的URL为了做一个带参数的帖子? 我认为Ruby隐藏在幕后。


我发现了问题! C#代码中的url变量是“http://www.carejobs.be/scripts/foxisapi.dll/carejobs.carejobs.importvacature/”它必须是“http://www.carejobs.be/scripts/foxisapi .dll / carejobs.carejobs.importvacature“不带反斜杠。

链接地址: http://www.djcxy.com/p/8011.html

上一篇: HTTP POST in .NET doesn't work

下一篇: sending HTTP parameters via POST method easily