Home AMX User Forum NetLinx Studio

Format of data portion of HTTP POST?

Sorry I'm having trouble finding a code example on this; I've got the rest of the HTTP connection stuff working, but I can't seem to find or figure out exactly how to format the data in the content portion of an HTTP POST call. Any help out there?

Thanks,

Comments

  • AMXJeffAMXJeff Posts: 450
    The content formating is really up to the server that is processing the data. But if you looking at where in the post request to put the content portion. Below the content portion "home=Cosby&favorite+flavor=flies" gets sent following an empty line (CR + LF). Hopefully this answers your question.


    POST /path/script.cgi HTTP/1.0
    From: frog@jmarshall.com
    User-Agent: HTTPTool/1.0
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 32

    home=Cosby&favorite+flavor=flies
    SEND_STRING dvSocket,"'POST /path/script.cgi HTTP/1.0',13,10"
    SEND_STRING dvSocket,"'From: [email]frog@jmarshall.com[/email]',13,10"
    SEND_STRING dvSocket,"'User-Agent: HTTPTool/1.0',13,10"
    SEND_STRING dvSocket,"'Content-Type: application/x-www-form-urlencoded',13,10"
    SEND_STRING dvSocket,"'Content-Length: 32',13,10"
    SEND_STRING dvSocket,"13,10"
    SEND_STRING dvSocket,"'home=Cosby&favorite+flavor=flies'"
    
  • OK, so it's just name/value pairs just like GET. No wonder I couldn't find it; woulda bit me if it were a snake.

    Now I'm wondering if I need URLEncode or I can use text/plain encoding. The only thing I'm up against is spaces in some text being submitted.
  • AMXJeffAMXJeff Posts: 450
    I believe it is required to encode the content, notice the "+" in the favorite+flavor.
  • I'm not so sure about that. I think it depends on the encoding you specify in the header. I'll test plain vs. encoded and report back...
  • AMXJeffAMXJeff Posts: 450
    I'm not so sure about that. I think it depends on the encoding you specify in the header. I'll test plain vs. encoded and report back...

    You are correct...
  • OK, I finally got most of the other parts of this project nailed down, now I'm back on the POST data thing. Can't get my server to pick up the POST data. It picks up POST data from another web page fine. Right now I've got:

    //NOTE httpcontent = "'room=11&user=fogled&problem=this+problem+list'"

    httpheader = "'POST /cobisapi.php HTTP/1.1',13,10";
    httpheader = "httpheader,'Connection: close',13,10";
    httpheader = "httpheader,'User-Agent: HTTPTool/1.0',13,10";
    httpheader = "httpheader,'Host: localhost',13,10"
    httpheader = "httpheader,'Content-Type: text/html',13,10";
    httpheader = "httpheader,'Content-Length: ',ITOA(LENGTH_STRING(httpcontent)),13,10";
    httpheader = "httpheader,13,10" // Extra Line Between Content

    //then I'm sending the httpheader,httpcontent to the IP server.

    The server just claims there's no POST data. Not sure what's up...
  • I've got it working with GET now, had to implement the URL-ization of text being sent. That means I might not ever get to testing details of using POST. Sorry.
  • travistravis Posts: 180
    I know you've already worked around it, but maybe someone else will come across this thread. Did you put a "13,10,13,10" after the post data?
  • jjamesjjames Posts: 2,908
    One of my favorite tools is LiveHTTPHeaders (http://livehttpheaders.mozdev.org/) for Firefox. Shows you all the goodies in the headers - I use this as the starting base for all HTTP traffic I work with.
Sign In or Register to comment.