Home AMX User Forum NetLinx Studio

HTTP Post Issue

I am using the NI-3000 to connect to a Andover Controls Netcontroller with a built in webserver. I can connect and use the HTTP Get command to pull in the information from a page. The webserver has Post capabilities as well which allow you to change information in the Netcontroller. This works fine when done from Internet Explorer but from the NI-3000, it doesnt work.
Here is the post command from my code:
SEND_STRING dvIP_CLIENT,"'POST /pe/selfclose HTTP/1.1 ',13,10,'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, */*',13,10,'Accept-Language: en-us',13,10,'Content-Type: application/x-www-form-urlencoded',13,10,'Accept-Encoding: gzip, deflate',13,10,'User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0; .NET CLR 1.0.3705)',13,10,'Content-Length: 12',13,10,'teststring=1',13,10,13,10"

I used Ethereal to capture the packet from the Internet Explorer machine and basically copied that Post command into Netlinx Studio.

Any ideas would be greatly appreciated.

Comments

  • Changed my code to the following and all is well (the trick is the CR,LF before the teststring=1 line)
    SEND_STRING dvIP_CLIENT,"
    'POST /pe/selfclose HTTP/1.1',13,10,
    'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, */*',13,10,
    'Accept-Language: en-us',13,10,
    'Content-Type: application/x-www-form-urlencoded',13,10,
    'Accept-Encoding: gzip, deflate',13,10,
    'User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0; .NET CLR 1.0.3705)',13,10,
    'Host: 10.10.10.110',13,10,
    'Content-Length: 12',13,10,
    'Connection: Keep-Alive',13,10,
    'Cache-Control: no-cache',13,10,13,10,
    'teststring=1'"
  • DHawthorneDHawthorne Posts: 4,584
    Yeah, that extra CR/LF pair is essentially a blank line, which is what the HTTP protocol designates as the end of your header. I forget, but you may need one at the end of your test string as well to signal the end of the session.
  • DHawthorne wrote:
    I forget, but you may need one at the end of your test string as well to signal the end of the session.

    Actually, the end of the POST body is indicated by the Content-Length header. Make sure that always changes to match the length of the body. You may have already done this, but I usually stick most of this in a function so I can just call POST('teststring=1') to construct the complete, including correct Content-Length header.

    Jeremy
  • AMXJeffAMXJeff Posts: 450
    HTTP Post

    You may be able to shrink the amount of header data you need to send with your post message. Keep in mind that you are informing the web server what YOUR capablities are with regards to HTTP. I surely doubt you are working with the same capablities as IE or Firefox.
  • ericmedleyericmedley Posts: 4,177
    AMXJeff wrote:
    You may be able to shrink the amount of header data you need to send with your post message. Keep in mind that you are informing the web server what YOUR capablities are with regards to HTTP. I surely doubt you are working with the same capablities as IE or Firefox.

    I've actually found that you do need to send all that chatter. Otherwise, depending upon the server, you get a 'you're browser is not worthy' message back.
  • Thanks for all the tips! This particular webserver is picky so all that nonsense is necessary.

    These forums are a great help to guys like me just starting out with more advanced programming.

    Thanks again.
Sign In or Register to comment.