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
Re: Winsock POST Problem GET WORKS
Whats running on localhost
Re: Winsock POST Problem GET WORKS
Quote:
Originally Posted by
5ms?
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";
?>
Re: Winsock POST Problem GET WORKS
Run this and see what you get.
Code:
<?php
$name = $_GET['name'];
echo $name;
?>
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
Re: Winsock POST Problem GET WORKS
Quote:
Originally Posted by
chunk
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")
Re: Winsock POST Problem GET WORKS
You're POSTing, but there's no Content-Length or data being sent.
Use GET
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.