Streaming byte array - WeOnlyDo Discussion board

Streaming byte array (wodHttpDLX)

by AtlantaGator, Thursday, August 24, 2017, 18:13 (30 days ago)

I need to send data as a Unicode UTF8 stream. Is this possible? What would the code look like?

Thanks

Streaming byte array

by Jasmine, Thursday, August 24, 2017, 19:28 (30 days ago) @ AtlantaGator

Hi.

I don't think you can stream data with wodHttpDLX, since it is based on fixed-length request and responses.

I assume you want to broadcast video using the component? I don't think it can be used in that way.

Kind regards,
Jasmine.

Streaming byte array

by AtlantaGator, Thursday, August 24, 2017, 21:16 (29 days ago) @ Jasmine

Jasmine,

Thanks for the reply.

What I meant by streaming is how data is sent through code.

I need to send a byte array to an api for credit card processing.

The data must be encoded (UTF8).

I am sending CC data plus the log in info.

I am unable to connect with the server.

I am able to connect using C# or VB.Net code without the HttpDLX object - using straight code.

BTW - I am using HttpDLX with VBA.

Thanks

Streaming byte array

by Jasmine, Thursday, August 24, 2017, 21:23 (29 days ago) @ AtlantaGator

Hi.

Can you paste your C# code with dummy data, so I can see how it looks like, and try to translate it to wodHttpDLX?

Jasmine.

Streaming byte array

by AtlantaGator, Thursday, August 24, 2017, 21:55 (29 days ago) @ Jasmine

Jasmine,

Thanks for your assistance.

Here is my code:

string mytran = "Login Credentials and CC Data";
 
 
            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
 
            // Create a request using a URL that can receive a post.
            WebRequest request = WebRequest.Create("webaddress");
           
            // Set the Method property of the request to POST.
            request.Method = "POST";
            // Create POST data and convert it to a byte array.
            byte[] byteArray = Encoding.UTF8.GetBytes(mytran);
            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/x-www-form-urlencoded";
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;
            Stream dataStream;
            try
            {
                // Get the request stream.
                dataStream = request.GetRequestStream();
                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);
                // Close the Stream object.
                dataStream.Close();
            }
 
            catch (Exception f)
            {
                MessageBox.Show(f.ToString());
            }
 
            // Get the response.
            WebResponse response = request.GetResponse();
            // Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();

Streaming byte array

by Jasmine, Thursday, August 24, 2017, 21:59 (29 days ago) @ AtlantaGator

Hi.

This should be pretty much straightforward, there's no stream of data, you can fill Request.Body with contents of stream. I assume stream isn't too large (in terms of megabytes) anyway.

So, something like this should do

Http1.Request.Headers.Add("Content-type: application/x-www-form-urlencoded")
Http1.Request.Body = "...put everything from the stream here"..
Http1.Post(URL)...

I think you don't need anything else. By default wodHttpDLX uses UTF8, but you can also specify it in Http1.Request.Charset if you wish, or you can write directly to Http1.Request.Filename (since Body actually internally reads/writes to it).

Can you try above?

Jasmine.

Streaming byte array

by AtlantaGator, Thursday, August 24, 2017, 23:23 (29 days ago) @ Jasmine

Jasmine,

I get the same response as before: I don't have permission to access the server.

Since the server credentials are in the body, my assumption is that the server cannot read the body properly, like it can from C#.

I tried with 2 body arguments:

in one case I encoded the string, the other I did not - I sent the string unaltered

Could it be that I am using VBA and not VB?

Thanks

Streaming byte array

by Jasmine, Thursday, August 24, 2017, 23:25 (29 days ago) @ AtlantaGator

Hi

VBA/VB cannot make a difference. Server don't know what you're using. Simply - data you are sending isn't same in both cases.

If you can somehow capture what you're sending in C# (such as with Fiddler) and then capture what you're sending with wodHttpDLX (with same Fiddler) you can spot the difference - and then just make the change in wodHttpDLX. It's usually just adding one header, changing body a bit or something simple.

Jasmine.

Streaming byte array

by AtlantaGator, Thursday, August 24, 2017, 23:40 (29 days ago) @ Jasmine

Jasmine,

Excellent idea - I will be back - thanks.

Streaming byte array

by AtlantaGator, Friday, August 25, 2017, 16:47 (29 days ago) @ AtlantaGator

Jasmine,

What kind of data does the Http1.Request.Body expect ?

Can it handle a byte array ?

Will it know that the argument is an array?

Thanks

Streaming byte array

by Jasmine, Friday, August 25, 2017, 19:25 (29 days ago) @ AtlantaGator

Hi

Request.Body is a string. So, you can convert byte array to it. However, it could be safer and easier to you to write to Request.Filename file directly, so there's no conversion needed, just dump byte array to it and wodHttpDLX will use it.

Jasmine.