Tôi đang gặp sự cố khi thực hiện việc này để mọi trợ giúp sẽ được đánh giá cao! Về cơ bản, request.body chứa XML hợp lệ cho Dịch vụ Web như sau:Làm cách nào để đăng XML lên RESTFUL Web Service bằng Net :: HTTP :: Post?
<somedata>
<name>Test Name 1</name>
<description>Some data for Unit testing</description>
</somedata>
... nhưng dịch vụ trả về XML trống. Lưu ý rằng các trường id được trả lại cho thấy rằng nó thực sự nhấn cơ sở dữ liệu, nhưng tên và mô tả các trường là con số không:
<somedata>
<id type='integer'>1</id>
<name nil='true'></name>
<description nil='true'></description>
</somedata>
Tôi đã tự thử nghiệm các dịch vụ RESTful sử dụng Poster và nó hoạt động tốt.
Đây là mã:
url = URI.parse('http://localhost:3000/someservice/')
request = Net::HTTP::Post.new(url.path)
request.body = "<?xml version='1.0' encoding='UTF-8'?><somedata><name>Test Name 1</name><description>Some data for Unit testing</description></somedata>"
response = Net::HTTP.start(url.host, url.port) {|http| http.request(request)}
#Note this test PASSES!
assert_equal '201 Created', response.get_fields('Status')[0]
Có ai có bất kỳ manh mối tại sao dữ liệu trong bài XML không tồn?
Nó sẽ giúp xem mã cho dịch vụ. –