Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7634921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:18:24+00:00 2026-05-31T07:18:24+00:00

I’m attempting to send an image and some text to a server at the

  • 0

I’m attempting to send an image and some text to a server at the same time.

I’m using WebRequest like the following to send text:

Dim ba As Byte() = Encoding.UTF8.GetBytes(query)

Dim wr As WebRequest = WebRequest.Create(Me.server_url)
wr.Method = "POST"
wr.ContentType = "application/x-www-form-urlencoded"
wr.ContentLength = ba.Length

And I have the following using WebClient for sending an image:

System.Net.WebClient Client = new System.Net.WebClient();

Client.Headers.Add("Content-Type", "binary/octet-stream");

byte[] result = Client.UploadFile(Properties.Settings.Default.script_url, 
"POST", "desktop.png");

But I cannot figure out how to do both at the same time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:18:26+00:00Added an answer on May 31, 2026 at 7:18 am

    After lots of searching, I found the following link:

    http://www.paraesthesia.com/archive/2009/12/16/posting-multipartform-data-using-.net-webrequest.aspx

    It is for C#, so here is a proof of concept I put together for VB:

    Dim boundry As String = "---------------------------" + DateTime.Now.Ticks.ToString("x")
        Dim request As WebRequest = WebRequest.Create(Globals.script_path + "uploader.php")
        request.Method = "POST"
        request.ContentType = "multipart/form-data; boundary=" + boundry
    
        Dim requestStream As Stream = request.GetRequestStream()
    
        '' send text data
        Dim data As Hashtable = New Hashtable()
        data.Add("text_input", "Hello World")
    
        For Each key As String In data.Keys
            Dim item As String = "--" + boundry + vbCrLf + "Content-Disposition: form-data; name=""" & key & """" + vbCrLf + vbCrLf + data.Item(key) + vbCrLf
            Dim itemBytes() As Byte = System.Text.Encoding.UTF8.GetBytes(item)
            requestStream.Write(itemBytes, 0, itemBytes.Length)
    
        Next
    
        '' send image data
        Dim file_header = "--" + boundry + vbCrLf + "Content-Disposition: form-data; name=""file_1"";filename=""file.png""" + vbCrLf + "Content-Type: image/png" + vbCrLf + vbCrLf
        Dim file_header_bytes() As Byte = System.Text.Encoding.UTF8.GetBytes(file_header)
        requestStream.Write(file_header_bytes, 0, file_header_bytes.Length)
        Dim ms As MemoryStream = New MemoryStream()
        timecard.screen_shot.Save(ms, ImageFormat.Png)
        Dim file_bytes() As Byte = ms.GetBuffer()
        ms.Close()
        requestStream.Write(file_bytes, 0, file_bytes.Length)
        Dim file_footer_bytes() As Byte = System.Text.Encoding.UTF8.GetBytes(vbCrLf)
        requestStream.Write(file_footer_bytes, 0, file_footer_bytes.Length)
    
    
        '' send
        Dim endBytes() As Byte = System.Text.Encoding.UTF8.GetBytes("--" + boundry + "--")
        requestStream.Write(endBytes, 0, endBytes.Length)
        requestStream.Close()
    
    
    
        Dim response As WebResponse = request.GetResponse()
        Dim reader As StreamReader = New StreamReader(response.GetResponseStream())
        Debug.WriteLine(reader.ReadToEnd())
    

    This, of course, is geared toward my personal needs, but I think it describes well what needs to be done. For the image, there is a filename. In this case, it is not an actual file. But the PHP receiving the file needs the data.

    Here is the PHP code I used to test this:

    <?php
    if (isset($_POST['text_input'])){
    echo $_POST['text_input'];
        $target_path = "screenshots/";
    
        $target_path = $target_path . basename( $_FILES['file_1']['name']); 
    
        if(move_uploaded_file($_FILES['file_1']['tmp_name'], $target_path)) {
            echo "The file ".  basename( $_FILES['file_1']['name']). 
            " has been uploaded";
        } else{
            echo "There was an error uploading the file, please try again!";
        }
    }else{
        echo "no dta";
    }
    

    ?>

    take care,
    lee

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.