Results 1 to 8 of 8

Thread: Winsock POST Problem GET WORKS

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Winsock POST Problem GET WORKS

    Hi
    i have this code and it works when the method is selected as GET but does not work when i select the POST method. What is wrong please help

    Code:
    Private Sub Winsock1_Connect()
    Dim Url As String
    Dim StrTh As String
    StrTh = "POST " & "http://localhost/winsock/winsock/post.php?name=" & Text1.Text & "&email=" & Text2.Text & "&msg=" & Text3.Text & vbCrLf
    StrTh = StrTh & "HTTP/1.0" & vbCrLf
    StrTh = StrTh & "Accept: */*" & vbCrLf
    StrTh = StrTh & "Accept: text/html" & vbCrLf & vbCrLf
    StrTh = StrTh & "Content-Type: application/x-www-form-urlencoded" & vbCrLf
     
    Winsock1.SendData StrTh
      
    End Sub

  2. #2
    Hyperactive Member
    Join Date
    Sep 2009
    Location
    Lost in thought
    Posts
    349

    Re: Winsock POST Problem GET WORKS

    Whats running on localhost

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2007
    Posts
    912

    Re: Winsock POST Problem GET WORKS

    Quote Originally Posted by 5ms? View Post
    Whats running on localhost
    a php page
    Code:
    <?php
    $name = $_GET['name'];
    $email = $_GET['email'];
    $msg = $_GET['msg'];
    $lnk = mysql_connect("localhost","root","mysql");
    $d = mysql_select_db("winsock");
    $sql = "INSERT INTO tbl_data (name, email, msg) VALUES ('$name','$email','$msg')";
    $res = mysql_query($sql);
    echo "Done";
    ?>

  4. #4
    Hyperactive Member
    Join Date
    Sep 2009
    Location
    Lost in thought
    Posts
    349

    Re: Winsock POST Problem GET WORKS

    Run this and see what you get.
    Code:
    <?php
    $name = $_GET['name'];
    echo $name;
    ?>

  5. #5
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: Winsock POST Problem GET WORKS

    Code:
    Private Sub Winsock1_Connect()
    Dim Url As String
    Dim StrTh As String
    StrTh = "GET /winsock/winsock/post.php?name=" & Text1.Text & "&email=" & Text2.Text & "&msg=" & Text3.Text & vbCrLf
    StrTh = StrTh & "Host: localhost" & vbnewline'dunno
    StrTh = StrTh & "HTTP/1.0" & vbCrLf
    StrTh = StrTh & "Accept: */*" & vbCrLf
    StrTh = StrTh & "Accept: text/html" & vbCrLf & vbCrLf
    StrTh = StrTh & "Content-Type: application/x-www-form-urlencoded" & vbCrLf
     
    Winsock1.SendData StrTh
      
    End Sub

  6. #6
    Hyperactive Member
    Join Date
    Sep 2009
    Location
    Lost in thought
    Posts
    349

    Re: Winsock POST Problem GET WORKS

    Quote Originally Posted by chunk View Post
    Hi
    i have this code and it works when the method is selected as GET but does not work when i select the POST method. What is wrong please help

    Code:
    Private Sub Winsock1_Connect()
    Dim Url As String
    Dim StrTh As String
    StrTh = "POST " & "http://localhost/winsock/winsock/post.php?name=" & Text1.Text & "&email=" & Text2.Text & "&msg=" & Text3.Text & vbCrLf
    StrTh = StrTh & "HTTP/1.0" & vbCrLf
    StrTh = StrTh & "Accept: */*" & vbCrLf
    StrTh = StrTh & "Accept: text/html" & vbCrLf & vbCrLf
    StrTh = StrTh & "Content-Type: application/x-www-form-urlencoded" & vbCrLf
     
    Winsock1.SendData StrTh
      
    End Sub
    May be
    Code:
    if($_SERVER['REQUEST_METHOD'] == "POST")

  7. #7
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: Winsock POST Problem GET WORKS

    You're POSTing, but there's no Content-Length or data being sent.

    Use GET

  8. #8
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Winsock POST Problem GET WORKS

    Uhm.... Your HTTP header seems a bit awkward. I don't know how important it is, but usually HTTP/1.0 is not on a new line, but is after the URL, with a space between them.

    And usually the only field with a double newline is the final field before the actual content. Plus you have two Accept fields, and no Accept-language, or content-length. So you're not posting content....

    Indeed, try GET.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width