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 8586265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:16:11+00:00 2026-06-11T22:16:11+00:00

i got the following form on an external service (someurl.com/xmlimport.html) which is protected by

  • 0

i got the following form on an external service (someurl.com/xmlimport.html) which is protected by basic auth.

<html>
<head><title>Upload</title></head>
<body>
<h1>Upload</h1>
<h2>XML Upload</h2>
<!--<form action="/cgi-bin/xmlimport.pl" method="post" accept-charset="UTF-8" enctype="multipart/form-data">-->
<form action="/cgi-bin/xmlimport.pl" method="post" enctype="multipart/form-data">
Datei: <input name="dateiname" type="file" size="100" accept="text/*">
<input type="submit" value="Absenden"/>
</form>
</body>
</html> 

I want to post xml files via ruby. This is what i got so far:

require "net/http"
require "uri"

uri = URI.parse('http://someurl.com/xmlimport.html')
file = "upload.xml"


post_body = []
post_body << "Content-Disposition: form-data; name='datafile'; filename='#{File.basename(file)}'rn"
post_body << "Content-Type: text/plainrn"
post_body << "rn"
post_body << File.read(file)


puts post_body

http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
request.basic_auth "user", "pass"
request.body = post_body.join
request["Content-Type"] = "multipart/form-data"

resp = http.request(request)

puts resp.body

The response is the content of my xml file and the form. But nothing is processed. What am I doing wrong?

Thanks in advance.

  • 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-06-11T22:16:12+00:00Added an answer on June 11, 2026 at 10:16 pm

    There are good examples on Ruby Inside’s Net::HTTP Cheat Sheet, including file uploads. Looks like you’re missing the file boundary. Their example:

    require "net/http"
    require "uri"
    
    # Token used to terminate the file in the post body. Make sure it is not
    # present in the file you're uploading.
    BOUNDARY = "AaB03x"
    
    uri = URI.parse("http://something.com/uploads")
    file = "/path/to/your/testfile.txt"
    
    post_body = []
    post_body << "--#{BOUNDARY}rn"
    post_body << "Content-Disposition: form-data; name="datafile"; filename="#{File.basename(file)}"rn"
    post_body << "Content-Type: text/plainrn"
    post_body << "rn"
    post_body << File.read(file)
    post_body << "rn--#{BOUNDARY}--rn"
    
    http = Net::HTTP.new(uri.host, uri.port)
    request = Net::HTTP::Post.new(uri.request_uri)
    request.body = post_body.join
    request["Content-Type"] = "multipart/form-data, boundary=#{BOUNDARY}"
    
    http.request(request)
    

    As an alternative, you may consider other http libraries that extract away the low-level cruft of Net::HTTP. Checkout faraday; you can do a file upload in just a few lines of code.

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

Sidebar

Related Questions

I've got the following HTML form. As you can see it's saving a file.
All, I've got the following page: http://tinyurl.com/7lzr6qo The original form code is: <form id=dj_feedback
All, I've got the following bit of HTML code to display a form with
I've got following auto generated HTML, which I can not change. This HTML displays
I've got the following JSF form: <h:form> <ui:repeat value=#{list.categories} var=cat> <h:selectOneRadio id=sel1Rad value=#{list.choose} layout=pageDirection>
I've got the following code for a search form, but how would I add
I've got the following bit of code to check if a form with multiple
I have got a the following problem: I have got multi-step form where in
I've got a complex form with rather a lot of css on the following
Just a follow up from a previous question. I've got the following form.. <body

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.