Ich möchte einige Daten von Arduino zu WebService (geschrieben in. NET), einige Temperaturdaten zu MS SQL Server zu speichern.Arduino - HTTP Beitrag funktioniert nicht
in Arduino Mein Code ist:
void PostarDados(String dados, String chamador) {
if (client.connect("mysite.com.br",80)) {
client.println(chamador);
client.println(F("Host: mysite.com.br"));
client.println(F("Content-Type: application/x-www-form-urlencoded"));
client.print(F("Content-Length: "));
client.println(dados.length());
client.println();
client.println(dados);
}
if (client.connected()) client.stop();
}
Wann Serien statt Client sendet, ich den folgenden Text am Erhalt:
POST /webservice.asmx/SetValoresTempUmidade HTTP/1.1
Host: mysite.com.br
Content-Type: application/x-www-form-urlencoded
Content-Length: 39
Chave=1&Temperatura=23.30&Umidade=42.20
Ich habe fähigen HTTP-POST in web.config zu machen HTTP POST möglich (Ich kann Webservice vom Browser erfolgreich aufrufen):
<location path="Webservice.asmx">
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
</location>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
Ich habe auch 01 eingestelltmeiner Webservice-Funktionen:
<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
Try
Dim A As New TBL_DADO
A.CHAVE_INICIO = Chave
A.DATA = Now
A.TEMPERATURA = Temperatura
A.UMIDADE = Umidade
ctx.TBL_DADOs.InsertOnSubmit(A)
ctx.SubmitChanges()
Catch ex As Exception
End Try
End Sub
Schließlich Ich versuche, einige Antwort vom Server mit dem folgenden Code (nicht erhalten etwas) zu erhalten:
erklärtwhile (client.connected()) {
while (client.available()) {
buffer[counter++] = client.read();
}
}
dass, ich habe zwei Fragen:
- Was mache ich falsch?
- Wie könnte ich das debuggen?