小程序
小游戏
企业微信
微信支付
扫描小程序码分享
在调用https://api.weixin.qq.com/wxaapi/broadcast/goods/add?access_token=[access_token],价格类型选择3
按文档上price 是现价price2是原价,price应该小于price2但是实际请求的时候,是相反的price是原价,price2是现价。按文档请求一直是price不合法。希望微信这边确认一下文档
2 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
使用这种方式,没问题
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.write(json.getBytes("UTF-8"));
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 {
if (out != null) {
out.close();
if (in != null) {
in.close();
if (httpConn != null) {
httpConn.disconnect();
} catch (IOException e) {
return "";
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
你好,我通过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的其他方式去添加成功
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
使用这种方式,没问题
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 "";
}
你好,我通过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的其他方式去添加成功