Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不指定Method,会丢弃header #9

Closed
samy1937 opened this issue May 17, 2020 · 6 comments
Closed

不指定Method,会丢弃header #9

samy1937 opened this issue May 17, 2020 · 6 comments

Comments

@samy1937
Copy link

不支持多重参数,比如下面的curl命令有多个-H参数

以下curl是从chrome浏览器中copy curl功能复制的

curl 'http://xxx.cc/admin/index.php?act=admin' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/80.0.3987.87 Chrome/80.0.3987.87 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9' -H 'Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7' -H 'Cookie: username=admin; token=b7ea3ec643e4ea4871dfe515c559d28bc0d23b6d9d6b22daf206f1de9aff13aeaa51591323199; addinfo=%7B%22chkadmin%22%3A1%2C%22chkarticle%22%3A1%2C%22levelname%22%3A%22%5Cu7ba1%5Cu7406%5Cu5458%22%2C%22userid%22%3A%221%22%2C%22useralias%22%3A%22admin%22%7D; timezone=8; Hm_lvt_12d9f8f1740b76bb88c6691ea1672d8b=1589004902,1589265192,1589341266,1589717172; Hm_lpvt_12d9f8f1740b76bb88c6691ea1672d8b=1589719525'

@guonaihong
Copy link
Contributor

ok,我看下原因。

@samy1937
Copy link
Author

samy1937 commented May 17, 2020

你可以测试 一下后台登录,在chrome浏览器里copy curl
测试代码,

package main

import (
	"fmt"
	"github.com/antlabs/pcurl"
	"github.com/guonaihong/gout"
)

func main() {
	req, err := pcurl.ParseAndRequest(`curl 'http://xxxx.cc/admin/index.php?act=admin' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/80.0.3987.87 Chrome/80.0.3987.87 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' -H 'Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7' -H 'Cookie: username=admin; token=b7ea3ec643e4ea4871dfe515c559d28bc0d23b6d9d6b22daf206f1de9aff13e51591323199; addinfo=%7B%22chkadmin%22%3A1%2C%22chkarticle%22%3A1%2C%22levelname%22%3A%22%5Cu7ba1%5Cu7406%5Cu5458%22%2C%22userid%22%3A%221%22%2C%22useralias%22%3A%22admin%22%7D; timezone=8; Hm_lvt_12d9f8f1740b76bb88c6691ea1672d8b=1589004902,1589265192,1589341266,1589717172; Hm_lpvt_12d9f8f1740b76bb88c6691ea1672d8b=1589719525'`)
	if err != nil {
		fmt.Printf("err:%s\n", err)
		return
	}



	body := ""
	err = gout.New().Debug(true).SetRequest(req).BindBody(&body).Do()

	fmt.Println(body)

}

@guonaihong
Copy link
Contributor

谢了。

@guonaihong
Copy link
Contributor

可以先指定-X 选项规避下。补丁估计明天会好。

package main

import (
	"fmt"
	"github.com/antlabs/pcurl"
	"github.com/guonaihong/gout"
)

func main() {
	req, err := pcurl.ParseAndRequest(`curl -X GET 'http://xxxx.cc/admin/index.php?act=admin' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/80.0.3987.87 Chrome/80.0.3987.87 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' -H 'Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7' -H 'Cookie: username=admin; token=b7ea3ec643e4ea4871dfe515c559d28bc0d23b6d9d6b22daf206f1de9aff13e51591323199; addinfo=%7B%22chkadmin%22%3A1%2C%22chkarticle%22%3A1%2C%22levelname%22%3A%22%5Cu7ba1%5Cu7406%5Cu5458%22%2C%22userid%22%3A%221%22%2C%22useralias%22%3A%22admin%22%7D; timezone=8; Hm_lvt_12d9f8f1740b76bb88c6691ea1672d8b=1589004902,1589265192,1589341266,1589717172; Hm_lpvt_12d9f8f1740b76bb88c6691ea1672d8b=1589719525'`)
	if err != nil {
		fmt.Printf("err:%s\n", err)
		return
	}



	body := ""
	err = gout.New().Debug(true).SetRequest(req).BindBody(&body).Do()

	fmt.Println(body)

}

@samy1937
Copy link
Author

samy1937 commented May 18, 2020

可以先指定-X 选项规避下。补丁估计明天会好。

package main

import (
	"fmt"
	"github.com/antlabs/pcurl"
	"github.com/guonaihong/gout"
)

func main() {
	req, err := pcurl.ParseAndRequest(`curl -X GET 'http://xxxx.cc/admin/index.php?act=admin' -H 'Connection: keep-alive' -H 'Cache-Control: max-age=0' -H 'Upgrade-Insecure-Requests: 1' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/80.0.3987.87 Chrome/80.0.3987.87 Safari/537.36' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' -H 'Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7' -H 'Cookie: username=admin; token=b7ea3ec643e4ea4871dfe515c559d28bc0d23b6d9d6b22daf206f1de9aff13e51591323199; addinfo=%7B%22chkadmin%22%3A1%2C%22chkarticle%22%3A1%2C%22levelname%22%3A%22%5Cu7ba1%5Cu7406%5Cu5458%22%2C%22userid%22%3A%221%22%2C%22useralias%22%3A%22admin%22%7D; timezone=8; Hm_lvt_12d9f8f1740b76bb88c6691ea1672d8b=1589004902,1589265192,1589341266,1589717172; Hm_lpvt_12d9f8f1740b76bb88c6691ea1672d8b=1589719525'`)
	if err != nil {
		fmt.Printf("err:%s\n", err)
		return
	}



	body := ""
	err = gout.New().Debug(true).SetRequest(req).BindBody(&body).Do()

	fmt.Println(body)

}

牛逼,测试了一下加上-X参数是可以的。
我的想法是为了方便,不需要改动curl参数,从chrome浏览器 f12 copy curl 命令就可以直接使用,这样就方便了太多太多了。

@guonaihong guonaihong mentioned this issue May 18, 2020
Merged
@guonaihong
Copy link
Contributor

guonaihong commented May 18, 2020

已经好了,go mod指向v0.0.2版本。新版本不需要自己加 -X选项。

@guonaihong guonaihong changed the title 不支持多重参数设置,比如多个-H 不指定Method,会丢弃header May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants