POST call on a mx7ck

aabfm
Posts: 31
Joined: Mon Aug 14, 2017 4:28 pm
Location: UK

POST call on a mx7ck

Post by aabfm » Wed Aug 30, 2017 4:58 pm

Hi Everyone,
On my previous topic "chipkit mx7ck calling "hello world" from webserver" I manage to have my mx7ck calling a webserver and displaying the info, i.e. implementing a webclient.
Now the next step is to identify my mx7ck (I actually have another one) in order to receive only the info that is related to it. In other words I want to contact my webserver which holds a php script, and this script is expecting the 'id' parameter sent via the POST method. It will then retrieve the info in xml format.
My problem is to call the script located at:
sending the POST parameter 'id' with the value "abcde".
1st step: get the ip from the DNS server.
Basically I want to be able to write the domain rather than the IP address of my webserver.
On the previous post I was using the following code to connect to the server:

Code: Select all

...
const char * server = "nnn.nnn.nnn.nnn";
unsigned short portServer = 80; 
...
switch(state)
    {
        case CONNECT:
            if(deIPcK.tcpConnect(server, portServer, tcpClient, &status))
            {
                state = WRITE;
            }
            break;
...
Does anyone know how to ?
Thanks in advance.

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: POST call on a mx7ck

Post by majenko » Wed Aug 30, 2017 5:17 pm

The DIIPcK class contains the function "resolveDomainName(const char *name, IPv4& ip)" which you can use to look up a domain name.

Code: Select all

IPv4 serverIP;
deIPcK.resolveDomainName("www.mywebserver.com", serverIP);
"serverIP" now should contain the IP address of the server.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

aabfm
Posts: 31
Joined: Mon Aug 14, 2017 4:28 pm
Location: UK

Re: POST call on a mx7ck

Post by aabfm » Wed Aug 30, 2017 5:30 pm

I will try it straight away.
Thx

aabfm
Posts: 31
Joined: Mon Aug 14, 2017 4:28 pm
Location: UK

Re: POST call on a mx7ck

Post by aabfm » Wed Aug 30, 2017 5:35 pm

I've just tried it as:

Code: Select all

deIPcK.resolveDomainName("www.startpage.com", serverIP);
deIPcK.tcpConnect(serverIP, portServer, tcpClient);
but it hangs...
Any ideas?

User avatar
majenko
Site Admin
Posts: 2164
Joined: Wed Nov 09, 2011 7:51 pm
Location: UK
Contact:

Re: POST call on a mx7ck

Post by majenko » Wed Aug 30, 2017 5:37 pm

Maybe the DNS lookup is failing? I think the function will return a `true` if it has worked, or `false` if it fails.
Why not visit my shop? http://majenko.co.uk/catalog
Universal IDE: http://uecide.org
"I was trying to find out if it was possible to only eat one Jaffa Cake. I had to abandon the experiment because I ran out of Jaffa Cakes".

aabfm
Posts: 31
Joined: Mon Aug 14, 2017 4:28 pm
Location: UK

Re: POST call on a mx7ck

Post by aabfm » Wed Aug 30, 2017 5:45 pm

Is there an option of forcing the DNS server to be something else such as OpenDNS IP?
Note: OpenDNS ip is 208.67.222.222

aabfm
Posts: 31
Joined: Mon Aug 14, 2017 4:28 pm
Location: UK

Re: POST call on a mx7ck

Post by aabfm » Wed Aug 30, 2017 5:51 pm

Tried this one but it also doesn't work:

Code: Select all

...
IPv4 opendns = {208,67,222,222};
...
deIPcK.setDNS(1, opendns);
deIPcK.resolveDomainName("www.google.com", serverIP);
deIPcK.tcpConnect(serverIP, portServer, tcpClient);

aabfm
Posts: 31
Joined: Mon Aug 14, 2017 4:28 pm
Location: UK

Re: POST call on a mx7ck

Post by aabfm » Wed Aug 30, 2017 8:15 pm

I've now tried both with and without DHCP but still the same response: none, it hangs...
Any idea?

aabfm
Posts: 31
Joined: Mon Aug 14, 2017 4:28 pm
Location: UK

Re: POST call on a mx7ck

Post by aabfm » Wed Aug 30, 2017 8:46 pm

Both:

Code: Select all

deIPcK.setDNS(1, opendns);
and

Code: Select all

deIPcK.resolveDomainName("www.google.com", serverIP);
returned FALSE... :(
Any ideas?

aabfm
Posts: 31
Joined: Mon Aug 14, 2017 4:28 pm
Location: UK

Re: POST call on a mx7ck

Post by aabfm » Wed Aug 30, 2017 9:55 pm

Latest test and... IT WORKED!!!!
Apparently there was a problem with my router...

Code: Select all

deIPcK.tcpConnect("www.mywebserver.com", portServer, tcpClient);
and the 2nd was also accomplished:

Code: Select all

String message = "POST /test01/results.php HTTP/1.1\nHost: http://www.mywebserver.com\nConnection: close\nContent-Length: 8\nContent-Type: application/x-www-form-urlencoded\n\nid=abcde\n\n";
Nice!
Last edited by aabfm on Thu Aug 31, 2017 10:03 am, edited 2 times in total.

Post Reply