0
votes

I've got a problem with creating an HTTP post request in .NET. When I do this request in ruby it does work.

When doing the request in .NET I get following error:

<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>

Does anyone knows how to fix this?

Ruby:

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;
2
If you step through the C# code, is there anything in the response object after you send request.GetResponse? Anything in the reader object after you step through the line of code after //Get the response stream?DOK
Why does the .NET error message complain about 'importvacature/' -- where does the / come from? What is the 'url' variable in the C# code -- are you sure it's set the same way as the Ruby code?Tim Robinson
I ran the code above and get a different error "U bent niet bevoegd vacatures in te voeren.". Not sure what that means? I used the same url as the Ruby code, and did not urlencode the 478.Sean
I got the same thing Sean, that translates to You are not authorized to enter jobs.TheCodeMonk
I found the problem! The url variable in the C# code was "carejobs.be/scripts/foxisapi.dll/…" It had to be "carejobs.be/scripts/foxisapi.dll/…" without the backslash.tom

2 Answers

0
votes

Don't you need the ? after the URL in order to do a post with parameters? I think that Ruby hides this behind the scenes.