faisalkh
asked on
ASP.net - VB.net Array
Hello,
I am trying to capture the HTTP Response, parse it and take appropriate actions based on the recieved data.
I hope someone can advise how can I go about doing this correct.
The response I get from the URL is
OK:22059
OR
OK:22059
OOS:2745
OOS:2752
OOS:2745
OOS:2752
If its only OK:22059, then I can easily capture and store it in the DB, the problem is when the response in more than 1 line.
I hope can someone advise how can I loop it through the array object so that if they more than 1 OOS item, it will do the same thing for all.
Thanks
F
I am trying to capture the HTTP Response, parse it and take appropriate actions based on the recieved data.
I hope someone can advise how can I go about doing this correct.
The response I get from the URL is
OK:22059
OR
OK:22059
OOS:2745
OOS:2752
OOS:2745
OOS:2752
If its only OK:22059, then I can easily capture and store it in the DB, the problem is when the response in more than 1 line.
Dim NetResultString() As String
If Not ResponseString Is Nothing And ResponseString <> "" Then
If ResponseString.Contains("OK") Then
NetResultString = ResponseString.Split(Environment.NewLine)
TransactionID = NetResultString(0).Substring(NetResultString(0).IndexOf(":") + 1, NetResultString(0).IndexOf(vbLf) - NetResultString(0).IndexOf(":") - 1)
If (TransactionID <> "") AndAlso (PrevOrderID <> OrderID) Then
UpdateWebOrderStatus(OrderID, "ORDER_SAVED_ON_Net", "WebSystem")
AddOrderNotes(OrderID, "Order Detail Saved Successfully. Net TransID: " & TransactionID, "WebSystem")
End If
If NetResultString(1) <> "" Then
LineItemID = NetResultString(1).Substring(NetResultString(0).IndexOf(":") + 1, NetResultString(1).IndexOf(vbLf) - NetResultString(1).IndexOf(":") - 1)
UpdateWebOrderStatus(OrderID, "ORDER_Net_MANUAL_STOCK", "WebSystem")
AddOrderNotes(OrderID, "Partial Order Detail Saved On Net Due To An Out Of Stock Item. ProductID: " & GetProdIDByNetID(LineItemID), "WebSystem")
CommonFunctions.SendEmail(My.Settings.AdminEmailAddress, My.Settings.OfficeAdminEmailAddress, "Net URL Data Post Error - Unable to save an Item record.", GetProdIDByNetID(LineItemID) & " is out of stock")
End If
' NetResultString(2)
' NetResultString(3)
' NetResultString(4)
End If
End If
I hope can someone advise how can I loop it through the array object so that if they more than 1 OOS item, it will do the same thing for all.
Thanks
F
ASKER
Hi,
I have tried that but it will only pick the first string from the below ie: "OK:22067" and come out of the loop.
>> Response = "OK:22067OOS:2752"
I am trying to loop it through so that next time it should go to the next if condition
Thanks
I have tried that but it will only pick the first string from the below ie: "OK:22067" and come out of the loop.
>> Response = "OK:22067OOS:2752"
I am trying to loop it through so that next time it should go to the next if condition
Thanks
Dim Response As String
For Each Response In ResponseString.Split(vbCrLf)
If Response.Contains("OK") Then
TransactionID = Response.Substring(Response.IndexOf(":") + 1, Response.IndexOf(vbLf) - Response.IndexOf(":") - 1)
AddOrderNotes(OrderID, "Order Detail Saved Successfully. Net TransID: " & TransactionID, "WebSystem")
ElseIf Response.Containts("OOS") Then
LineItemID = Response.Substring(Response.IndexOf(":") + 1, Response.IndexOf(vbLf) - Response.IndexOf(":") - 1)
AddOrderNotes(OrderID, "Partial Order Detail Saved On Net Due To An Out Of Stock Item. ProductID: " & GetProdIDByNetID(LineItemID), "WebSystem")
End If
End If
>>> Response = "OK:22067OOS:2752"
That's because there does not seem to be a line break between the elements.
That's because there does not seem to be a line break between the elements.
ASKER
Please can you see the attachment? You will notice that there is a carriage return between the strings
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
For Each response in ResponseString.Split(VBCRL
'Above code here to deal with each line of response string
Next