收藏
回答

微信直播商品库添加商品api,文档参数是不是写错了?

在调用https://api.weixin.qq.com/wxaapi/broadcast/goods/add?access_token=[access_token],价格类型选择3

按文档上price 是现价price2是原价,price应该小于price2但是实际请求的时候,是相反的price是原价,price2是现价。按文档请求一直是price不合法。希望微信这边确认一下文档

回答关注问题邀请回答
收藏

2 个回答

  • 2020-07-19

    使用这种方式,没问题

    public static String postByJson(String url, int connectTimeout, int readTimeout, Map<String, String> param, String json) {

    OutputStream out = null;

    InputStream in = null;

    HttpURLConnection httpConn = null;

    try {

    URL urlcon = new URL(url);

    httpConn = (HttpURLConnection) urlcon.openConnection();

    httpConn.setDoInput(true);

    httpConn.setDoOutput(true);

    httpConn.setRequestMethod("POST");

    httpConn.setUseCaches(false);

    httpConn.setRequestProperty("Content-Type", "application/json");

    httpConn.setRequestProperty("Connection", "Keep-Alive");// 维持长连接

    httpConn.setRequestProperty("Charset", "UTF-8");

    httpConn.setRequestProperty("user-agent", "java.net.http");

    httpConn.setConnectTimeout(connectTimeout);

    httpConn.setReadTimeout(readTimeout);

    httpConn.connect();

    if (param != null && !param.isEmpty()) {

    StringBuilder sb = new StringBuilder();

    for (Map.Entry<String, String> e : param.entrySet()) {

    if (e.getKey() != null && e.getKey().trim().length() > 0) {

    sb.append(e.getKey() + "=" + e.getValue() + "&");

    }

    }

    out = httpConn.getOutputStream();

    out.write(sb.substring(0, sb.length() - 1).getBytes("utf-8"));

    out.flush();

    } else if (null != json) {

    out = httpConn.getOutputStream();

    out.write(json.getBytes("UTF-8"));

    out.flush();

    }

    InputStream is = httpConn.getInputStream();

    byte[] bytes = new byte[1024];

    int length = bytes.length;

    int remain = length;

    while (true) {

    int count = is.read(bytes, length - remain, remain);

    if (count == -1) {

    break;

    }

    remain -= count;

    if (remain == 0) {

    length = bytes.length + 1024;

    remain = 1024;

    byte[] c = new byte[length];

    System.arraycopy(bytes, 0, c, 0, bytes.length);

    bytes = c;

    }

    }

    return new String(bytes, "utf-8").trim();

    } catch (Exception e) {

    e.printStackTrace();

    } finally {

    try {

    if (out != null) {

    out.close();

    }

    if (in != null) {

    in.close();

    }

    if (httpConn != null) {

    httpConn.disconnect();

    }

    } catch (IOException e) {

    e.printStackTrace();

    }

    }

    return "";

    }

    2020-07-19
    有用
    回复
  • 林裕斌
    林裕斌
    2020-04-28

    你好,我通过postman去试,确实可以提交成功,但是通过自己写的post提交,就会出现503,这个是我的

    public static string HttpPost(string postUrl, string jsonData)

            {

                try

                {

                    HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(postUrl);

                    httpRequest.Method = "POST";

                    httpRequest.ContentType = "application/json"

                    byte[] data = Encoding.UTF8.GetBytes(jsonData);

                    httpRequest.ContentLength = data.Length;

                    Stream requestStream = httpRequest.GetRequestStream();

                    requestStream.Write(data, 0, data.Length);

                    requestStream.Close();

                    Stream responseStream = null;

                    responseStream = httpRequest.GetResponse().GetResponseStream(); //到这里就直接卡住然后报503

                    string stringResponse = string.Empty;

                    using (StreamReader responseReader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8")))

                    {

                        stringResponse = responseReader.ReadToEnd();

                    }

                    responseStream.Close();

                    return stringResponse;

                }

                catch(Exception e)

                {

                    return ""

                }

            }

    我这里面是否弄错了什么,你有没有通过除了postman的其他方式去添加成功

    2020-04-28
    有用
    回复 2
    • 张永
      张永
      2020-05-19
      你解决了吗。咋解决的。
      2020-05-19
      回复
    • 林裕斌
      林裕斌
      2020-05-20回复张永
      解决了,Expect100Continue的问题,在上面我发的那段的基础加上 httpRequest.ServicePoint.Expect100Continue = false;这个属性默认是true,必须设为false才不会503或者not found
      2020-05-20
      回复
登录 后发表内容
问题标签