client url

CloseableHttpClient httpClient = HttpClients.createDefault();
String entityStr = null;
CloseableHttpResponse response = null;
HttpPost httpPost = new HttpPost("http://localhost:8080/test/downLoadFiletoClient");
List<NameValuePair> list = new LinkedList<>();
BasicNameValuePair param1 = new BasicNameValuePair("UUID", UUID);
list.add(param1);
UrlEncodedFormEntity entityParam = new UrlEncodedFormEntity(list, "UTF-8");
httpPost.setEntity(entityParam);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
package adapi import ( "crypto/md5" "encoding/json" "errors" "fmt" "io/ioutil" "net" "net/http" "net/url" "strconv" "time" ) var AdApi = NewAdApi("aasd@##SDfsd1213") type adApi struct { key string client *http.Client url string } func NewAdApi(key string) adApi { var netTransport = &http.Transport{ DialContext: (&net.Dialer{ Timeout: 3 * time.Second, // 连接超时时间 KeepAlive: 10 * time.Second, }).DialContext, TLSHandshakeTimeout: 1 * time.Second, ResponseHeaderTimeout: 3 * time.Second, ExpectContinueTimeout: 1 * time.Second, MaxIdleConnsPerHost: 10, MaxIdleConns: 100, IdleConnTimeout: 10 * time.Second, } var netClient = &http.Client{ Timeout: time.Second * 30, Transport: netTransport, } adApi := adApi{ key: key, client: netClient, url: "http://adapi.ysjgames.com/", } return adApi } type Account struct { AdvertiserId string `json:"advertiser_id"` Uid string `json:"uid"` Type string `json:"type"` AdvertiserName string `json:"advertiser_name"` AccessToken string `json:"access_token"` } const ( AccountTTGD = "1" //头条光动 AccountTTJY = "2" //头条嘉娱 AccountGDT = "3" //广点通 AccountKS = "4" //快手 AccountWB = "6" //微博 ) func (a *Account) CheckForTouTiao() bool { if a.Uid != AccountTTGD && a.Uid != AccountTTJY { return false } return true } func (a *Account) CheckForGdt() bool { if a.Uid != AccountGDT { return false } return true } func (aa adApi) Accounts() ([]Account, error) { params := map[string]string{ "mod": "ad", "type": "accounts", } aa.InjectSign(params) values := url.Values{} for k, v := range params { values.Set(k, v) } accountUrl := aa.url + "?" + values.Encode() resp, err := aa.client.Get(accountUrl) if err != nil { return nil, err } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, err } respData := struct { Code int `json:"code"` Accounts []Account `json:"accounts"` }{} err = json.Unmarshal(body, &respData) if err != nil { return nil, err } if respData.Code != 0 { return nil, errors.New("code != 0 :" + string(body)) } return respData.Accounts, nil } func (aa adApi) InjectSign(params map[string]string) { current := time.Now().Unix() sign := md5.Sum([]byte(strconv.FormatInt(current, 10) + aa.key)) params["time"] = strconv.FormatInt(current, 10) params["sign"] = fmt.Sprintf("%x", sign) } 使用php实现当前代码,而且要用curl请求而不是Guzzle HTTP扩展
最新发布
06-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值