Look, I do not understand this. If I change the connection tag I receive the following error:
CODE:
#include <SPI.h>
#include <Ethernet2.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte server[] = { 192, 168, 0, 101 };
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 177);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
Serial.println(Ethernet.localIP());
// if you get a connection, report back via serial:
if (client.connect(server, 8312)) {
soapEnvelope();
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
String soapEnvelope()
{
Serial.println("In SOPA");
Serial.println("Connected to Server");
client.println(F("POST /WS_PLANILLA.Service1.svc HTTP/1.1"));
client.println(F("Host:192.168.0.101:8312"));
client.println(F("Content-Type:text/xml; charset=utf-8"));
client.println(F("Content-Length:204"));
client.println("");
client.print(F("<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:tem=""http://tempuri.org/"">"));
client.print(F("<soapenv:Header/>"));
client.print(F("<soapenv:Body>"));
client.print(F("<tem:ConsultaID/>"));
client.print(F("</soapenv:Body>"));
client.print(F("</soapenv:Envelope>"));
client.println(F("Connection: close"));
client.println("");
Serial.println("MAKE REQUEST DONE");
}
void loop() {
while (client.connected()) {
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
}
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while (true);
}
ANSWER:
connecting...
192.168.0.103
In SOPA
Connected to Server
MAKE REQUEST DONE
HTTP/1.1 400 Bad Request
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
Date: Mon, 26 Feb 2018 15:02:23 GMT
Content-Length: 0
And that's fine, the request is wrong, but if I put the connection tag where it should be, I simply do not receive anything.
CODE
#include <SPI.h>
#include <Ethernet2.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte server[] = { 192, 168, 0, 101 };
// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 0, 177);
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
Serial.println(Ethernet.localIP());
// if you get a connection, report back via serial:
if (client.connect(server, 8312)) {
soapEnvelope();
} else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
String soapEnvelope()
{
Serial.println("In SOPA");
Serial.println("Connected to Server");
client.println(F("POST /WS_PLANILLA.Service1.svc HTTP/1.1"));
client.println(F("Host:192.168.0.101:8312"));
client.println(F("Content-Type:text/xml; charset=utf-8"));
client.println(F("Content-Length:204"));
client.println(F("Connection: close"));
client.println("");
client.print(F("<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:tem=""http://tempuri.org/"">"));
client.print(F("<soapenv:Header/>"));
client.print(F("<soapenv:Body>"));
client.print(F("<tem:ConsultaID/>"));
client.print(F("</soapenv:Body>"));
client.print(F("</soapenv:Envelope>"));
client.println("");
Serial.println("MAKE REQUEST DONE");
}
void loop() {
while (client.connected()) {
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
}
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while (true);
}
ANSWER:
connecting...
192.168.0.103
In SOPA
Connected to Server
MAKE REQUEST DONE