Hi,
I'm trying to get data from WCF webservices on port 5053. And It will return in JSON format.
Here my snippet code :
char server[] = "example.com"; // Example DNS server
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, ip);
}
Serial.println("connecting...");
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 5053)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET http://example.com:5053/test.svc/json/1234 HTTP/1.1");
client.println("Host: example.com:5053");
client.println("Content-Type: application/json; charset=utf-8");
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available())
{
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while(true);
}
}
When I run the arduino, is only show "Connected" but no result.
If using the web browers, it will show : {"JSONDataResult":"You request the product with ID: 1234"}.
Did I do something wrong?