|
I am using VB.2013.
Code :
Dim MydataStream As Stream = Nothing
MydataStream = MyWebClient.OpenWrite(address:=MySend2URL, method:="POST")
Dim postArray As Byte() = Encoding.ASCII.GetBytes(postData)
MydataStream.Write(postArray, 0, postArray.Length)
MydataStream.Close()
Dim reader As New StreamReader(MydataStream)
How can I get a response that can be used and not the Stream is not readable error.
|
|
|
|
|
Your previous line of code closed the stream, so how do you expect to read it?
|
|
|
|
|
It also happens if I do not close it.
If postData = NIL Then
MydataStream = MyWebClient.OpenRead(address:=MySend2URL)
Else
MydataStream = MyWebClient.OpenWrite(address:=MySend2URL, method:="POST")
MydataStream.Write(postArray, 0, postArray.Length)
End If
Dim ThisResponse As String = NIL
Dim reader As New StreamReader(MydataStream)
|
|
|
|
|
Your stream is opened for write access, or there is nothing to read. You will need to use your debugger to collect more information.
|
|
|
|
|
What information?
I would think that it would be normal to write and expect a response.
|
|
|
|
|
QuickBooksDev wrote: I would think that it would be normal to write and expect a response. Of course, you are correct. But debugging is what we have to do when our applications do not behave normally.
|
|
|
|
|
I understand that I have been coding for many years but I have never used WebClient before and do not know what to look for. I was expecting that is there is some setting or parameter that needs to be set to get the response.
Do you have any explicit things to look for? Or do you have any code that does something similar that you can provide?
|
|
|
|
|
What kind of response are you expecting to get back from the POST? Is it a file? Just a string? Some kind of value? What?
Using (rs = MyDataStream.GetResponse().GetResponseStream())
Using (reader = New StreamReader(rs))
Dim content = reader.ReadToEnd()
End Using
End Using
This might not compile. I'm translating from C# and I'm really tired right now...
|
|
|
|
|
It doesn't compile. Please send c# code. GetResponse is not a member of io stream and rs not defined. How should MyDataStream and rs be defined?
I am not sure of the response. The doc that I have on this service is very limited and not written for .Net.
|
|
|
|
|
|
|
The doc is where I started and copied the code from their examples. I just does not show getting a response from OpenWrite.
There is very little of my code to actually debug.
I am not sure if I am sending the wrong data to the service or that the WebClient is coded wrong.
|
|
|
|
|
QuickBooksDev wrote: I am not sure if I am sending the wrong data to the service And all i can say in response, once again, is that you need to do some debugging to find out. There is no detail in your question that can help anyone here to guess what might be going wrong.
|
|
|
|
|
If you don't close it the stream will still contain the data that is in the postarray, with the "current position" at the end of the stream. If you want to read it, you'd need to reset the position. Then again, why would you read from the stream the data that you just wrote to it?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I don't want to read from what I wrote. The data I wrote in not in the stream but in postArray.
MydataStream.Write(postArray, 0, postArray.Length)
From the MS example Steam = MyWebClient.OpenWrite(... It was my assumption that this was be a response like it is if it were an OpenRead (which does work).
The MSDN sample doesn't show it processing a response.
|
|
|
|
|
|
So what are you saying by just putting in that link? That is the sample we used to do OpenReads which works when there is no postdata.
Do I need to do an OpenRead after the OpenWrite?
If so should the same Steam be used or another? If the same should the stream be closed after the write and before the read?
|
|
|
|
|
I have not tried this myself but that is what I assume. Maybe the HttpWebRequest Class[^] would suit your purpose better.
|
|
|
|
|
Found what I had to do.
I had to get the target server people to trace what they were getting and tell me what was wrong. Eventually found out that I had to add the below ContentType and remove the leading "?" from the postData.
None of the debugging in the .net code was of any help since without the below the postdata was being sent as 1 field and they were not returning anything if the postdata was invalid.
MyWebRequest.ContentType ="application/x-wwww.form-urlencoded"
|
|
|
|
|
hello..
please help me to connect microsoft fingerprint with vb2010..
|
|
|
|
|
You haven't given us ANY information to go on.
Read the documentation on the scanner you have, contact the manufacturer and see if they have a SDK for it. If so, get that and read the documentation on it.
|
|
|
|
|
There's an hardware abstraction layer in Windows. We don't talk to the devices directly, one installs the driver that comes with the device.
How applications interact with it will depend on the driver. Some vendors provide an SDK as a download on their website, if there doesn't appear to be one, mail them.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello anyone,
I have a Windows form developed in vb.net Framework.The form size is large enough that it can not display completely on the screen and therefore horizontal and vertical scroll bar are there.
Now i want to save this Windows form in pdf format so that i can take print out in future.
Currently i am able to save only screen shot not complete form.
So can any of you please tell me how to do that ?
Thnakyou in advance.
Regards,
Jitendra Singh
|
|
|
|
|
|
Hi,
Forget printing.
Right now I am only concerned to save my Winform in pdf format.
Since i am new to vb,net so if you can provide some code snippet than that would be better for me.
Thankyou in advance.
Regards,
Jitendra Singh
|
|
|
|