I'm trying to view the HTTP request being sent/received to twitter. I tried downloading fiddler4 but it's not registering the 401 error and I'm only receiving the 500 page error. Any ideas on how to view the request being sent so I can trouble shoot the reason?
I tried viewing the site as localhost, 127.0.0.1, and machinename.
Dim oAuthRequest As New Dictionary(Of String, String)
oAuthRequest.Add("resource_url", "https://api.twitter.com/oauth/request_token")
oAuthRequest.Add("oauth_callback", Server.UrlEncode("https://www.site.com/callback/"))
oAuthRequest.Add("oauth_consumer_key", "xxxxxxxx")
oAuthRequest.Add("oauth_nonce", Convert.ToBase64String(New ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString())))
oAuthRequest.Add("oauth_signature_method", "HMAC-SHA1")
oAuthRequest.Add("oauth_timestamp", CInt((DateTime.UtcNow - New DateTime(1970, 1, 1)).TotalSeconds).ToString)
oAuthRequest.Add("oauth_token", "authorization_code")
Dim baseFormat As String = "oauth_callback=""{0}""&oauth_consumer_key=""{1}""&oauth_nonce=""{2}""&oauth_signature_method=""HMAC-SHA1""&oauth_timestamp=""{3}""&oauth_version=""" & Uri.EscapeDataString("1.0") & """"
Dim baseString As String = String.Format(baseFormat,
oAuthRequest("oauth_callback"),
oAuthRequest("oauth_consumer_key"),
oAuthRequest("oauth_nonce"),
oAuthRequest("oauth_timestamp"))
baseString = String.Concat("POST&", Uri.EscapeDataString(oAuthRequest("resource_url")), "&", Uri.EscapeDataString(baseString))
oAuthRequest.Add("oauth_signature", SHA1Base64Hash("xxxxxxx&", baseString))
Dim authHeaderFormat As String = "OAuth oauth_callback=""{0}"",oauth_consumer_key=""{1}"",oauth_nonce=""{2}"",oauth_signature=""{3}"",oauth_signature_method=""HMAC-SHA1"",oauth_timestamp=""{4}"",oauth_version=""1.0"""
Dim authHeader As String = String.Format(authHeaderFormat,
Uri.EscapeDataString(oAuthRequest("oauth_callback")),
Uri.EscapeDataString(oAuthRequest("oauth_consumer_key")),
Uri.EscapeDataString(oAuthRequest("oauth_nonce")),
Uri.EscapeDataString(oAuthRequest("oauth_signature")),
Uri.EscapeDataString(oAuthRequest("oauth_timestamp")))
ServicePointManager.Expect100Continue = False
Dim request As HttpWebRequest = CType(WebRequest.Create(oAuthRequest("resource_url")), HttpWebRequest)
request.Headers.Add("Authorization", authHeader)
request.Method = "POST"
request.ContentType = "application/x-www-form-urlencoded"
Try
Dim response As WebResponse = request.GetResponse()
Catch ex As Exception
Text.text = ex.Message
End Try
If Fiddler shows you a HTTP/500 rather than a HTTP/401, that's because the server is returning HTTP/500. Unless you tell it to do so, Fiddler does not invent responses.
Related
I get a response from the reCapture and need to read the "success" value, but get the error:
Public member 'success' on type 'Dictionary(Of String,Object)' not found.
Response
{ "success": true, "challenge_ts": "2017-02-20T13:55:01Z", "hostname": "domain.co.uk" }
I'm trying to access it using:
data.success
Full code
Dim Response As String = Request.Form("g-recaptcha-response")
Dim Valid As Boolean = False
Dim req As HttpWebRequest = DirectCast(WebRequest.Create(Convert.ToString("https://www.google.com/recaptcha/api/siteverify?secret=" & SecretKey & "&response=") & Response), HttpWebRequest)
Try
Using wResponse As WebResponse = req.GetResponse()
Using readStream As New StreamReader(wResponse.GetResponseStream())
Dim jsonResponse As String = readStream.ReadToEnd()
Dim js As New JavaScriptSerializer()
Dim data As Object = js.Deserialize(Of Object)(jsonResponse)
Valid = Convert.ToBoolean(data.success)
End Using
End Using
Return Valid
Catch ex As WebException
Throw ex
End Try
Got the answer in the end so in case this helps anyone it's:
data("success")
Rather than
data.success
This is my code it is in vb.net . I did'nt get response from soap request , i have no idea what is the wrong with this code , its showing 500 Internal Server Error.
Dim webRequest__1 As WebRequest = WebRequest.Create("https://login.twinfield.com/webservices/session.asmx?wsdl")
Dim httpRequest As HttpWebRequest = DirectCast(webRequest__1, HttpWebRequest)
httpRequest.Method = "POST"
httpRequest.ContentType = "application/soap+xml;charset=UTF-8;action='http://www.twinfield.com/Logon'"
httpRequest.Host = "login.twinfield.com"
httpRequest.Headers.Add("SOAPAction:https://login.twinfield.com/webservices/session.asmx")
httpRequest.ProtocolVersion = HttpVersion.Version11
httpRequest.Credentials = CredentialCache.DefaultCredentials
Dim requestStream As Stream = httpRequest.GetRequestStream()
'Create Stream and Complete Request
Dim streamWriter As New StreamWriter(requestStream, Encoding.ASCII)
' <soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:twin='http://www.twinfield.com/'>
Dim soapRequest As New StringBuilder("<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' xmlns:twin='http://www.twinfield.com/'><soap:Header/><soap:Body><twin:Logon><twin:user>dgf</twin:user> <twin:password>cfg</twin:password><twin:organisation>dfd</twin:organisation></twin:Logon></soap:Body></soap:Envelope>")
'soapRequest.Append(" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" ")
'soapRequest.Append("xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""><soap:Body>")
'soapRequest.Append("<GetMyName xmlns=""http://tempuri.org/""><name>Sam</name></GetMyName>")
'soapRequest.Append("</soap:Body></soap:Envelope>")
streamWriter.Write(soapRequest.ToString())
streamWriter.Close()
'Get the Response
Dim htttpresponse As HttpWebResponse = CType(httpRequest.GetResponse(), HttpWebResponse)
'Dim wr As HttpWebResponse = CType(httpRequest.GetResponse(), HttpWebResponse)
'DirectCast(httpRequest.GetResponse(), HttpWebResponse)
Dim srd As New StreamReader(htttpresponse.GetResponseStream())
Dim resulXmlFromWebService As String = srd.ReadToEnd()
'Return resulXmlFromWebService
To call a soap web service, I think it is better to add the service url as a web reference (i.e. name as twinfield) in visual studio. Then you can use the service as a function as below.
twinfield.Session s = new twinfield.Session();
twinfield.LogonAction ac;
string cl = "";
twinfield.LogonResult k = s.Logon("dsfa", "Sadfsa", "sdfas", out ac, out cl);
I have a part of code that sends a post httprequest to weburl and then the response is again in post method , how can I get the posted data from httpresponse :
Dim request1 As HttpWebRequest = HttpWebRequest.Create("some url here" & str)
request1.Method = "POST"
request1.CookieContainer = cookie
enc = New System.Text.UTF8Encoding()
postdatabytes = enc.GetBytes(postdt)
request1.ContentType = "application/x-www-form-urlencoded"
' request1.ContentType = "application/json"
request1.ContentLength = postdatabytes.Length
'Dim strn As New StreamWriter(request1.GetRequestStream())
'strn.Write(postdt)
'strn.Close()
Using stream = request1.GetRequestStream()
stream.Write(postdatabytes, 0, postdatabytes.Length)
End Using
Dim r As String
Dim response1 As HttpWebResponse = request1.GetResponse()
If response1.Method = "POST" Then
'' here I want to get response data
End If
After a long searching I didnt find any answer ...
Am trying to create a simple page that connects to an external website, logs in, and then passes a bunch of parameters.
When I run the page I get a bad request 400 error and when I check using Fiddler I can see there are both 401 and 400 errors being returned. Under 'Auth' in Fiddler I see:
"No Proxy-Authorization Header is present.
No Authorization Header is present." < Is this relevant? As when I test using PHP cUrl the page can log in fine and Fiddler says the same under Auth.
Dim UserName As String = "testusername"
Dim password As String = "testpassword"
Dim siteCredentials As New NetworkCredential(UserName, password)
Dim URLAuth As String = "http://service.someurl.com/process.xml"
Dim postString As String = String.Format("customeremailaddress={0}&customername={1}&referenceid={2}&languagecode={3}&expirydays={4}", customeremailaddress, customername, referenceid, languagecode, expirydays)
Dim postBytes As Byte() = Encoding.UTF8.GetBytes(postString)
Const contentType As String = "application/x-www-form-urlencoded"
System.Net.ServicePointManager.Expect100Continue = False
Dim cookies As New CookieContainer()
Dim webRequest__1 As HttpWebRequest = TryCast(WebRequest.Create(URLAuth), HttpWebRequest)
webRequest__1.Method = "POST"
webRequest__1.ContentType = contentType
webRequest__1.CookieContainer = cookies
webRequest__1.ContentLength = postBytes.Length
webRequest__1.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1"
webRequest__1.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
webRequest__1.Referer = "http://service.someurl.com/process.xml"
webRequest__1.Credentials = siteCredentials
Try
Dim requestStream As Stream = webRequest__1.GetRequestStream()
requestStream.Write(postBytes, 0, postBytes.Length)
Dim testcapture As String = requestStream.ToString
Dim thing As String = "stop"
Dim responseReader As New StreamReader(webRequest__1.GetResponse().GetResponseStream())
Dim responseData As String = responseReader.ReadToEnd()
responseReader.Close()
webRequest__1.GetResponse().Close()
Catch ex As Exception
Lbl_ConnTest_error.Text = ex.Message
End Try
Seems the login credentials are not being passed what am I doing wrong? I am obviously using vb in an asp.net application but am connecting to an XML file held on Linux Apache, does this have any implications at all?
Fiddler appears to be doing strange things for me now so if anyone else can see anything using Fiddler a link to the test file is here:
http://www.filemanage.co.uk/Pubs/Default.aspx
I'm trying to post these variable threw an engine which gives back a responce but while testing it localy on VStudio everything is normal. When i upload it on the server the post request are not precessed.
Dim webStream As Stream
Dim s As HttpWebRequest`enter code here`
Dim res As HttpWebResponse
Dim webResponse = ""
Dim enc As UTF8Encoding
Dim postdata As String
Dim postdatabytes As Byte()
s = HttpWebRequest.Create("http://private.pin-pay.com:3902/")
enc = New System.Text.UTF8Encoding()
postdata = "PN=961" & ddlPhone.SelectedValue & txtMobilePhone.Text & "&TI=" & TransactionID.Text
postdatabytes = enc.GetBytes(postdata)
s.Method = "POST"
s.ContentType = "application/x-www-form-urlencoded"
s.ContentLength = postdatabytes.Length
Using stream = s.GetRequestStream()
stream.Write(postdatabytes, 0, postdatabytes.Length)
End Using
res = s.GetResponse()
webStream = res.GetResponseStream()
Dim webStreamReader As New StreamReader(webStream)
While webStreamReader.Peek >= 0
webResponse = webStreamReader.ReadToEnd()
End While