Note that there are some explanatory texts on larger screens.

plurals
  1. POPosting using POST from C# over https
    text
    copied!<p>After wasting two days with <a href="https://stackoverflow.com/questions/768030/simple-httpwebrequest-over-ssl-https-gives-404-not-found-under-c">this question</a> (and trying to make it work), I've decided to take a step back and ask a more basic question, because apparently there's something I don't know or I'm doing wrong. </p> <p>The requirements are simple, <em>I need to make an HTTP post (passing a few values) over https</em> from C#.</p> <p>The website (if given the appropriate values) will return some simple html and a response code. (i'll show these later). </p> <p>It's really <strong>that</strong> simple. The "webservice" works. I have a php sample that works and successfully connects to it. I also have a Dephi "demo" application (with source code) that also works. And finally I have the demo application (binary) from the company that has the "service", that also works of course.</p> <p>But I need to do it through C#. That that sounds so simple, it is not working.</p> <p>For testing purposes I've created a simple console app and a simple connect method. I've tried like 7 different ways to create an HTTP request, all more or less the same thing, different implementation (Using WebClient, using HttpWebRequest, etc).</p> <p>Every method works, <strong>except</strong> when the URI begins with 'https'. </p> <p>I get a webexception saying that the remote server returned 404. I've installed Fiddler (as suggested by a SO user), and investigated a little bit the traffic. The 404 is because I am passing something wrong, because as I mentioned later, the 'service' works. I'll talk about the fiddler results later.</p> <p>The URL where I have to POST the data is: <a href="https://servicios.mensario.com/enviomasivo/apip/" rel="nofollow noreferrer">https://servicios.mensario.com/enviomasivo/apip/</a></p> <p>And this is the POST data: (the values are fakes)</p> <p>usuario=SomeUser&amp;clave=SomePassword&amp;nserie=01234567890123456789&amp;version=01010000&amp;operacion=220</p> <p>The server might return a two/three lines response (sorry about the spanish, but the company is from Spain). Here's a sample of a possible response:</p> <pre><code>HTTP/1.1 200 OK Content-Type: text/plain 01010000 100 BIEN 998 </code></pre> <p>And here's another</p> <pre><code>HTTP/1.1 200 OK Content-Type: text/plain 01010000 20 AUTENTIFICACION NEGATIVA Ha habido un problema en la identificación ante el servidor. Corrija sus datos de autentificacion. </code></pre> <p>The 1st one means OK, and the 2nd one is Auth Failure.</p> <p>As you can see the task is quite <em>easy</em>, only it doesn't work. If I use fiddler, I see that there's some sort of SSL stuff going on in the connection and then everything works fine. However, as far as I've read, .NET handles all that stuff for us (<em>yes, i've added the callback to always validate invalid certs</em>). I don't understand what I'm doing wrong. I can post/email the code, but what I'd like to know is very simple:</p> <p><strong>How can you make a POST over SSL using C# and a "simple" HttpWebRequest and later have the response in a string/array/Whatever for processing?</strong></p> <p>Trust me when I say I've been googling and Stackoverflowing for two days. I don't have any sort of proxy. The connection passes through my router. Standard ports. Nothing fancy. My Machine is inside a VMWare virtual machine and is Windows Vista, but given that the sample applications (php, delphi, binary) all work without an issue, I cannot see that as a problem).</p> <p>The different samples (sans the binary) are available <a href="http://www.mensario.com/SEMPROTP/SDK/" rel="nofollow noreferrer">here</a> if anyone wants to take a look at them.</p> <p>I'd appreciate any help. If anyone wants to try with a "real" username, I have a demo user and I could pass you the user/pass for testing purposes. I only have <em>one</em> demo user (the one they gave me) and that's why I'm not pasting it here. I don't want to flood the user with tests ;)</p> <p>I've tried (within the samples) using UTF8 and ASCII, but that didn't change anything. </p> <p>I am 100% positive that there's something I have to do with SSL and I am not doing it because I don't know about it. </p> <p>Thanks in <strong>advance</strong>.</p> <p>Martín.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload