hello again
i need your help
i made a simple app that calls a webmethod and gets a json string as response
everything worked fine up untill yesterday when suddenlly it stop working for no reason
when the code tries to get the response the message i get is
"A first chance exception of type 'System.Net.WebException' occurred in System.dll"
what i dont understand is why did it stop working in both the form app i made and a dll that i use to a different project the code and libraries used in both of them are exacly the same and no change was made for the last 3 months
here is the code
as soon as the code get to :
Dim httpResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
i get the "A first chance exception of type 'System.Net.WebException' occurred in System.dll" error
i need your help
i made a simple app that calls a webmethod and gets a json string as response
everything worked fine up untill yesterday when suddenlly it stop working for no reason
when the code tries to get the response the message i get is
"A first chance exception of type 'System.Net.WebException' occurred in System.dll"
what i dont understand is why did it stop working in both the form app i made and a dll that i use to a different project the code and libraries used in both of them are exacly the same and no change was made for the last 3 months
here is the code
Code:
Imports System.Net
Imports System.IO
Imports System.Text
Imports Newtonsoft.Json
Imports System.Web
Public Class Form1
Public Class Get_all_closed_bills_class
Property ClientToken As String
Property AccessToken As String
Property StartUtc As String
Property EndUtc As String
End Class
Public Function Get_all_closed_bills(Request As String,
Username As String,
Password As String,
AccessToken As String,
ClientToken As String,
StartUtc As String,
EndUtc As String)
Dim strRequest As String = Request
Dim strJsonData As String
Dim objhttpWebRequest As HttpWebRequest
Dim obj_Get_all_closed_bills As New Get_all_closed_bills_class
obj_Get_all_closed_bills.ClientToken = ClientToken
obj_Get_all_closed_bills.AccessToken = AccessToken
obj_Get_all_closed_bills.StartUtc = StartUtc
obj_Get_all_closed_bills.EndUtc = EndUtc
strJsonData = JsonConvert.SerializeObject(obj_Get_all_closed_bills, Newtonsoft.Json.Formatting.Indented)
Try
Dim MyCredentials As System.Net.NetworkCredential
MyCredentials = New System.Net.NetworkCredential(Username, Password)
Dim httpWebRequest = DirectCast(WebRequest.Create(strRequest), HttpWebRequest)
httpWebRequest.Credentials = MyCredentials
httpWebRequest.ContentType = "application/json"
httpWebRequest.Method = "POST"
Using streamWriter = New StreamWriter(httpWebRequest.GetRequestStream())
streamWriter.Write(strJsonData)
streamWriter.Flush()
streamWriter.Close()
End Using
objhttpWebRequest = httpWebRequest
Catch ex As Exception
Console.WriteLine("Send Request Error[{0}]", ex.Message)
Return Nothing
End Try
Return GetResponse(objhttpWebRequest)
End Function
Private Function GetResponse(ByVal httpWebRequest As HttpWebRequest) As String
Dim strResponse As String = "Bad Request:400"
Try
Dim httpResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
Using streamReader = New StreamReader(httpResponse.GetResponseStream())
Dim result = streamReader.ReadToEnd()
strResponse = result.ToString()
End Using
Catch ex As Exception
Console.WriteLine("GetResponse Error[{0}]", ex.Message)
Return ex.Message
End Try
Return strResponse
End Function
Private Sub btnRetrieve_Click(sender As System.Object, e As System.EventArgs) Handles btnRetrieve.Click
Dim strResponse As String
' request
' username
' password
' AccessToken
' ClientToken
' StartUtc
' EndUtc
'strResponse =
Dim start_date As String = Format(StartDate.Value, "yyyy-MM-ddThh:mm:ss.00Z")
Dim end_date As String = Format(EndDate.Value, "yyyy-MM-ddThh:mm:ss.00Z")
strResponse = Get_all_closed_bills("https://demo.mews.li/api/connector/v1/bills/getAllClosed", _
"connector-api@mews.li", _
"connector-api", _
"C66EF7B239D24632943D115EDE9CB810-EA00F8FD8294692C940F6B5A8F9453D", _
"E0D439EE522F44368DC78E1BFB03710C-D24FB11DBE31D4621C4817E028D9E1D", _
start_date, _
end_date)
TextBox1.Text = strResponse
End Sub
End Class
as soon as the code get to :
Dim httpResponse = DirectCast(httpWebRequest.GetResponse(), HttpWebResponse)
i get the "A first chance exception of type 'System.Net.WebException' occurred in System.dll" error
Last edited: