Skip to content
This repository has been archived by the owner on Dec 25, 2020. It is now read-only.

不能正常使用POST请求 #4

Closed
gyje opened this issue Nov 1, 2019 · 2 comments
Closed

不能正常使用POST请求 #4

gyje opened this issue Nov 1, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@gyje
Copy link

gyje commented Nov 1, 2019

code:

package main

import (
	"github.com/eddieivan01/nic"
	"log"
	"fmt"
)

func post_test(num string){
	url := "http://xxx.action?depth=2"
	session := &nic.Session{}
	resp, err := session.Post(url, nic.H{
		Headers: nic.KV{
			"Accept": "application/json, text/javascript, */*; q=0.01",
			"X-Requested-With": "XMLHttpRequest",
			"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36",
			"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
		},
		Data: nic.KV{
			"$containerNo_like": num,
			"page": "1",
			"rows": "30",
		},
		AllowRedirect: true,
	})
	if err != nil{
		log.Println(err.Error())
	}
	fmt.Println(resp.Text)
}

func main(){
	post_test("1234567")
}

结果一直没反应,已经排除服务器问题。

@EddieIvan01
Copy link
Owner

我尝试抓取的请求包:

POST /index.action?depth=2 HTTP/1.1
Host: 127.0.0.1
User-Agent: golang-nic/0.2.0
Connection: close
Content-Length: 42
Accept: application/json, text/javascript, */*; q=0.01
Content-Type: application/x-www-form-urlencoded
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Accept-Encoding: gzip

%24containerNo_like=1234567&page=1&rows=30

猜测某些服务器对于重复的Content-Type头会返回400,可能与此有关。
也可以尝试和正常数据包进行对比确定问题

关于添加请求头时重复字段的处理将在下个版本修复

@EddieIvan01 EddieIvan01 added the bug Something isn't working label Nov 9, 2019
@EddieIvan01
Copy link
Owner

已修复,本地测试已正常。如果有后续问题,可以reopen该issue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants