Problems with Go post json

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Want to write a client with go, send a JSON data to the Java server interface,

As a result, the body received by Java is always empty, but the server written by Python is ok

Online Search method

Which: Some of the methods have been tried,

Type requestbody struct {

status String ' JSON: ' status '

Region []string ' JSON: ' Region '

Percent string ' JSON: ' Percent '

task_id string ' JSON: ' task_id '

}

B, err: = json. Marshal (Rbody)

Body: = bytes. Newbuffer ([]byte (b))

(1)

RESP, err: = http. Post (URL, "Application/json", body)

(2)

RESP, err: = http. Post (URL, "application/x-www-form-urlencoded", body)


(3)

Client: = &http. client{}

Req, _: = http. Newrequest ("POST", url, body)

Req. Header.set ("Content-type", "Application/json")

RESP, err: = client. Do (req)

Not at all, and finally, try and

Req, _: = http. Newrequest ("POST", url, body)

Switch

Req, _: = http. Newrequest ("POST", URL, strings. Newreader (string (b)))

Okay, OK.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.