I am wanting to POST some data from Arduino to WebService (written in .NET), intending to save some temperature data to MS SQL Server.

My code in arduino is:

void PostarDados(String dados, String chamador) {
  if (client.connect("mysite.com.br",80)) {
    client.println(F("Host: mysite.com.br"));
    client.println(F("Content-Type: application/x-www-form-urlencoded"));
    client.print(F("Content-Length: "));
  if (client.connected()) client.stop();

When sending to Serial instead of client, I am obtaining the following text:

POST /webservice.asmx/SetValoresTempUmidade HTTP/1.1
Host: mysite.com.br
Content-Type: application/x-www-form-urlencoded
Content-Length: 39


I have enabled HTTP POST in web.config to make HTTP POST possible (I can successfully invoke webservice from browser):

  <location path="Webservice.asmx">
          <add name="HttpGet"/>
          <add name="HttpPost"/>
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Allow-Headers" value="Content-Type" />

I have also set ScriptMethod to my webservice functions:

<WebMethod()> <ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)>
Public Sub SetValoresTempUmidade(Chave As Integer, ByVal Temperatura As Double, ByVal Umidade As Double)
    Dim ctx As New DataClassesDataContext
        Dim A As New TBL_DADO
        A.CHAVE_INICIO = Chave
        A.DATA = Now
        A.TEMPERATURA = Temperatura
        A.UMIDADE = Umidade
    Catch ex As Exception
    End Try
End Sub

Finally, I am trying to get some response from server using the following code (not receiving anything):

while (client.connected()) {
  while (client.available()) {
   buffer[counter++] = client.read();

Explained that, I have two questions:

  1. What am I doing wrong?
  2. How could I debug this?
  • I think PostarDados() is missing to \r\n\r\n at the end of the HTTP message Aug 22, 2016 at 11:02
  • Thanks, but it didn't work
    – Nizam
    Aug 22, 2016 at 12:34
  • You're hiding any errors in your webservice method as there is nothing between your Catch and End Try. My first action would be to add logging in there to see if anything is going wrong there. Aug 22, 2016 at 16:50
  • I would also try to code up a simple GET request webservice - just to simplify things and to make sure the requests are getting to the webservice at all... Aug 22, 2016 at 16:51

1 Answer 1



byte server[] = {XX, XX, XX, XX}; //IP
if (client.connect(server,80)) {

instead of

if (client.connect("mysite.com.br",80)) {



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.