aaa
aaa

Reputation: 715

Lantronix XPORT - TCP/IP tunnel to send HTTP POST requests

I have a XPORT (TCP/IP serial tunnel device) connected to my microcontroller (PIC18), this way I can send serial messages which are transformed into TCP/IP packages. I've enabled TCP/IP packaging, so that all characters will be put in one TCP/IP package until nothing is received for a short period of time.

I've succesfully sent a HTTP GET request through the tcp/ip tunnel. Though when I try to send a HTTP POST request, I either get a "400 Bad request" or my apache server crashes...

I think this behaviour is because of the line-ends not being, "right".

My code:

Delay1KTCYx(160);
xportSendTextNoLine("C192.168.200.18/80\n");//Manual connect to server (xport command)

Delay1KTCYx(160);//Wait for TCP/IP packaging.
xportSendTextNoLine("POST /debug.php HTTP/1.1");
xportSend(0x0D);//Carriage return.
xportSend(0x0A);//New line

xportSendTextNoLine("Host: 192.168.200.18");
xportSend(0x0D);//Carriage return.
xportSend(0x0A);//New line

xportSendTextNoLine("Content-Type: application/x-www-form-urlencoded");
xportSend(0x0D);//Carriage return.
xportSend(0x0A);//New line
xportSend(0x0D);//Carriage return.
xportSend(0x0A);//New line

xportSendTextNoLine("Grower=2&SiteId=99&Time=2015021108291700&Usertag=testuser&Action=0");
xportSend(0x0D);//Carriage return.
xportSend(0x0A);//New line
xportSend(0x0D);//Carriage return.
xportSend(0x0A);//New line
Delay1KTCYx(160);//Wait for TCP/IP packaging.

Wireshark output (simplified):

>POST /debug.php HTTP/1.1[0x0D][0x00][0x0A]
      Host: 192.168.200.18[0x0D][0x00][0x0A]
      etc.

<HTTP/1.1 400 Bad Request

Wireshark output (complete):

Wireshark ouput (complete)

It seems that a 0x0D (Carriage Return) to the Lantronix Xport causes a 0x00 to be sent after it. Which would lead to the webserver not being able to interpret the request.

I've just sent a tech support question to the Lantronix support, but I'd also like to know if anyone can tell me if:

Verifying the output of the microcontroller:

Test 2

Settings of the XPORT are the same as TERMINAL and should be the same as the MCU (otherwise it wouldn't receive the same):

Settings xport

MCU serial setup:

    RCSTA2bits.SPEN   = 1;   //Serial port enable
    TRISGbits.TRISG2  = 1;   //RG2 input (RX)
    TRISGbits.TRISG1  = 0;   //RG1 output (TX)
    ANCON2bits.ANSEL18= 0;   //DIGITAL!
    ANCON2bits.ANSEL19= 0;

    IPR3bits.RC2IP = 1;//High-priority  Rx interrupts
    PIE3bits.RC2IE = 1;//Enable         Rx interrupt

    TXSTA2 = 0b00100000;
    RCSTA2 = 0b10010000;
    BAUDCON2 = 0b01000000;//Receive operation active.

    SPBRG2  = 12;   // 9615 (0.16% error) (8Mhz)

Upvotes: 0

Views: 2401

Answers (1)

aaa
aaa

Reputation: 715

I have finally found the solution!

After some (logical) thinking I found that it would be the problem of the XPORT. But what could be the problem? I disabled all features of which I thought that might interfere (even though I thought this would be unlogical to cause this kind of error) and after saving, the POST request just popped up nicely in my server...

See the settings here (might want to open it in a new tab):

xport settings

Upvotes: 1

Related Questions