Sending HTTP1.1 POST

Hi,
Been trying to send HTTP 1.1 POST’s using xojo.net.httpSocket but the event stops mid way through, in my code I have lines that only acts like a “Log” so I can see whats going on like “WebPage1.ListBox1.AddRow(“Task”)” and that how I noticed that it stops mid way through. A lot of code is commented out.

My code: (located in a HandelSpecialURL event)

'Allowing me to change values on a specifc Session "Only for testing perpuses"
Dim sessionContext As New WebSessionContext(Self.SessionWithIdentifier(SessionId))
'Capture the POST from paypal and store it in the PaypalData Property
PaypalData = Request.Entity
WebPage1.ListBox1.AddRow("Raw Data: " + PaypalData)

//Decode the string from paypal
Dim dec As String 
dec = DecodeURLComponent(PaypalData)
WebPage1.ListBox1.AddRow("Decoded Data : " + dec)   //NOTE# this only "Prints" the data to a Listbox so I can see whats going on


If PaypalData = "" Then
  WebPage1.ListBox1.AddRow("ERROR: No data")
Elseif PaypalData = "VERIFIED" then
  WebPage1.ListBox1.AddRow("VERIFIED")
Else
  Request.Status = 200
  WebPage1.ListBox1.AddRow("Sent Status 200")  //NOTE# this only "Prints" the data to a Listbox so I can see whats going on
  
  'Return True
  'WebPage1.ListBox1.AddRow("Returned True")  //NOTE# this only "Prints" the data to a Listbox so I can see whats going on
  
  'Build Postback String by adding "cmd=_notify-validate"
  PaypalData = "cmd=_notify-validate&" + PaypalData     //This adds cmd=_notify-validate to the paypal entity preping it to be sent back for verification
  WebPage1.ListBox1.AddRow("Built validate String: " + PaypalData)   //NOTE# this only "Prints" the data to a Listbox so I can see whats going on
  
  'Convert to JSON text  //I only do this to avoid ERROR: Parameter "Value" expects type Text, but this is type String
  'Dim json As Text
  'json = GenerateJSON(PaypalData)
  'WebPage1.ListBox1.AddRow("Converted to json")  //NOTE# this only "Prints" the data to a Listbox so I can see whats going on
  
  Dim txt As Text = PaypalData.ToText
  
  'Convert to Memory Block  //Xojo.Net.HTTPSocket whats content in a Memoryblock and ... this code does that I believe
  Dim data As Xojo.Core.MemoryBlock
  data = Xojo.Core.TextEncoding.UTF8.ConvertTextToData(txt)
  WebPage1.ListBox1.AddRow("Converted to Memory Block")  //NOTE# this only "Prints" the data to a Listbox so I can see whats going on
  
  'Send it
  Dim mySocket As New xojo.Net.HTTPSocket
  mySocket.SetRequestContent(data, "application/x-www-form-urlencoded")
  mySocket.Send("POST", "https://ipnpb.paypal.com/cgi-bin/webscr")
  WebPage1.ListBox1.AddRow("Data Sent Back")   //NOTE# this only "Prints" the data to a Listbox so I can see whats going on
End If

It stops at Build Postback String and does not continue.
Any Ideas why this is happening?

Thanks

Are you getting an exception?

Unfortunately, For me to test the app I have to compile it and upload it to my web server but to usually run the project and test what I can before compiling

Put some code in app.UnhandledException to write the exception to a file.

Thanks, @Greg O’Lone,
I got this:
BadDataException

String_ToText
String.$ToText%y%s
App.Event_HandleSpecialURL%b%oo
WebApplication._HandleHTTPRequest%%oo<_HTTPServer.HTTPRequestContext>
_CGIGateway.GatewayRequestThread.Event_Run%%o<_CGIGateway.GatewayRequestThread>

any ideas?

Yup. That means that the data that’s being returned isn’t UTF8 even though you’re saying that it is when you are converting to text.

What would be the best way to prep the following to be sent via POST:

payment_type=instant&payment_date=Sat%20Aug%2005%202017%2015%3A04%3A56%20GMT%2B0200%20%28South%20Africa%20Standard%20Time%29&payment_status=Completed&payer_status=verified