0

I am trying to write figure out how can we call API method from and using asp.net c# with following parameters and form-data, its working in Postman:

enter image description here

You can see it has four parameters named: action,user-id,type,format Whereas it has a form-data parameter named: data (needs to be a file)

I am able to do all using WebClient but unable to figure out POSTING file in data parameter of form-data. Here is what i tried

Public Function SetFingerData(UserId As Integer, FingerData1 As String) As Byte()
    Dim Request = "http://" + IP + ":" + Port + "/device.cgi/credential?" + "action=set&type=1&user-id=" + UserId.ToString
    Using client As New WebClient
        Dim data = New NameValueCollection()
        data.Add("data", FingerData1)
        Dim result1 = client.UploadValues(Request, data)
        Return result1
    End Using
End Function

Any help!!!

Prasanth
  • 173
  • 1
  • 10
  • So where is the code you have tried? –  May 12 '18 at 10:37
  • 1
    What I usually recommend is to use a sniffer like wireshark or fiddler and compare Postman results with c# app. – jdweng May 12 '18 at 11:09
  • @jdweng though i tried using wireshark and fiddler i always failed to trace the request. May be i don't know how to use use it. – Prasanth May 12 '18 at 11:12
  • 1
    Are you using any filters? You need to look at the http messages with the IP address of your PC and the destinations. Does it work with Postman? If it does then you have to look at the TCP connection. Http uses TCP as the transport layer. So if you are not getting http then the connection is failing at the TCP. You can use cmd.exe >Netstat -a to get a list of connections which included http. Make sure the Postman is closed since you can only have one connection at a time. You should be able to see the Postman connection when it is working using Netstat. – jdweng May 12 '18 at 11:37

0 Answers0