• 关于

    同时估计法出现问题怎么解决

    的搜索结果

回答

post请求有多种,不贴代码不好看,这是数字格式转换异常 这是我的代码,帮我看一下,谢谢!!publicclassHttpUtils{publicstaticStringsubmitPostData(StringstrUrlPath,Map<String,String>params,Stringencode){byte[]data=getRequestData(params,encode).toString().getBytes();//获得请求体try{URLurl=newURL(strUrlPath);HttpURLConnectionhttpURLConnection=(HttpURLConnection)url.openConnection();httpURLConnection.setConnectTimeout(3000);//设置连接超时时间httpURLConnection.setDoInput(true);httpURLConnection.setDoOutput(true);httpURLConnection.setRequestMethod("POST");httpURLConnection.setUseCaches(false);httpURLConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");httpURLConnection.setRequestProperty("Content-Length",String.valueOf(data.length));OutputStreamoutputStream=httpURLConnection.getOutputStream();outputStream.write(data,0,data.length);outputStream.close();intresponse=httpURLConnection.getResponseCode();if(response==HttpURLConnection.HTTP_OK){InputStreaminputStream=httpURLConnection.getInputStream();returndealResponseResult(httpURLConnection.getInputStream(),encode);}}catch(IOExceptione){e.printStackTrace();return"err:"+e.getMessage().toString();}return"-1";}privatestaticStringBuffergetRequestData(Map<String,String>params,Stringencode){StringBufferstringBuffer=newStringBuffer();try{for(Map.Entry<String,String>entry:params.entrySet()){stringBuffer.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(),encode)).append("&");}stringBuffer.deleteCharAt(stringBuffer.length()-1);}catch(Exceptione){e.printStackTrace();}returnstringBuffer;}privatestaticStringdealResponseResult(InputStreaminputStream,Stringencode){StringresultData=null;ByteArrayOutputStreambyteArrayOutputStream=newByteArrayOutputStream();byte[]data=newbyte[1024];intlen=0;if(inputStream!=null){try{while((len=inputStream.read(data))!=-1){byteArrayOutputStream.write(data,0,len);}resultData=newString(byteArrayOutputStream.toByteArray(),encode);}catch(IOExceptione){e.printStackTrace();}}returnresultData;}} publicclassMainActivityextendsAppCompatActivity{privateButtonpost_btn;privateTextViewresult;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);result=(TextView)findViewById(R.id.result);post_btn=(Button)findViewById(R.id.btn);post_btn.setOnClickListener(newView.OnClickListener(){@OverridepublicvoidonClick(Viewview){post_btn_OnClick(view);}});}privatevoidpost_btn_OnClick(Viewview){StringstrRecSmsMsg="收短信测试";RecSmsToPost(strRecSmsMsg);}privatevoidRecSmsToPost(StringstrRecSmsMsg){StringstrNowDateTime=getNowDateTime("yyyy-MM-dd|HH:mm:ss");Map<String,String>params=newHashMap<String,String>();params.put("shopId","371");params.put("advertAreaId","1");//params.put("mode","iisue");//params.put("call","shopService.qryAdvertList");//params.put("params","{"advertAreaId":"1","shopId":"371"}\n");//params.put("version","1.0.0");StringstrUrlPath="http://192.168.31.177:8081"+"DataTime="+strNowDateTime;StringstrResult=HttpUtils.submitPostData(strUrlPath,params,"utf-8");result.setText(strResult);}privateStringgetNowDateTime(StringstrFormat){if(strFormat==""){strFormat="yyyy-MM-ddHH:mm:ss";}Datenow=newDate();SimpleDateFormatdateFormat=newSimpleDateFormat(strFormat);returndateFormat.format(now);}} StringstrUrlPath="http://192.168.31.177:8081"+"DataTime="+strNowDateTime; &DateTime...这个是打印出现在的时间 URL=URI?queryString URI与queryString之间要加?(问号),也就是URI+?+queryString才是完整的URL格式。 queryString的多个参数之间用&连接。 另外,你的上述代码封装是“不支持同时提交多个同名参数的”。这个问题解决了但我现在点击按钮直接就停止运行URL由URI与“可选的queryString”联合组成。当有queryString时,URI与queryString之间要有问号(?)。而你的程序中显然是缺少了问号的。我这里面没有什么URL=URI啊能不能说详细点我是个安卓菜鸟,还有要怎么才能同时提交多个数据呢 这是现在的代码但运行点击按钮的时候直接停止运行 publicclassHttpUtils{publicstaticStringsubmitPostData(StringstrUrlPath,Map<String,String>params,Stringencode){byte[]data=getRequestData(params,encode).toString().getBytes();//获得请求体try{URLurl=newURL(strUrlPath);HttpURLConnectionhttpURLConnection=(HttpURLConnection)url.openConnection();httpURLConnection.setConnectTimeout(3000);//设置连接超时时间httpURLConnection.setDoInput(true);httpURLConnection.setDoOutput(true);httpURLConnection.setRequestMethod("POST");httpURLConnection.setUseCaches(false);httpURLConnection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");httpURLConnection.setRequestProperty("Content-Length",String.valueOf(data.length));OutputStreamoutputStream=httpURLConnection.getOutputStream();outputStream.write(data);//outputStream.close();intresponse=httpURLConnection.getResponseCode();if(response==HttpURLConnection.HTTP_OK){InputStreaminptStream=httpURLConnection.getInputStream();returndealResponseResult(inptStream);}}catch(IOExceptione){e.printStackTrace();return"err:"+e.getMessage().toString();}return"-1";}privatestaticStringBuffergetRequestData(Map<String,String>params,Stringencode){StringBufferstringBuffer=newStringBuffer();try{for(Map.Entry<String,String>entry:params.entrySet()){stringBuffer.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue(),encode)).append("&");}stringBuffer.deleteCharAt(stringBuffer.length()-1);}catch(Exceptione){e.printStackTrace();}returnstringBuffer;}privatestaticStringdealResponseResult(InputStreaminputStream){StringresultData=null;ByteArrayOutputStreambyteArrayOutputStream=newByteArrayOutputStream();byte[]data=newbyte[1024];intlen=0;try{while((len=inputStream.read(data))!=-1){byteArrayOutputStream.write(data,0,len);}}catch(IOExceptione){e.printStackTrace();}resultData=newString(byteArrayOutputStream.toByteArray());returnresultData;}}   publicclassMainActivityextendsAppCompatActivity{privateButtonpost_btn;privateTextViewresult;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);result=(TextView)findViewById(R.id.result);post_btn=(Button)findViewById(R.id.btn);post_btn.setOnClickListener(newView.OnClickListener(){@OverridepublicvoidonClick(Viewview){post_btn_OnClick(view);}});}privatevoidpost_btn_OnClick(Viewview){StringstrRecSmsMsg="收短信测试";RecSmsToPost(strRecSmsMsg);openToast("提交测试完成");}privatevoidRecSmsToPost(StringstrRecSmsMsg){StringstrNowDateTime=getNowDateTime("yyyy-MM-dd|HH:mm:ss");Map<String,String>params=newHashMap<String,String>();//params.put("shopId","371");//params.put("advertAreaId","1");params.put("mode","iisue");params.put("call","shopService.qryAdvertList");params.put("params","{"advertAreaId":"1","shopId":"371"}\n");params.put("version","1.0.0");StringstrUrlPath="http://192.168.31.177:8081"+"?DateTime="+strNowDateTime;StringstrResult=HttpUtils.submitPostData(strUrlPath,params,"utf-8");result.setText(strResult);}privateStringgetNowDateTime(StringstrFormat){if(strFormat==""){strFormat="yyyy-MM-ddHH:mm:ss";}Datenow=newDate();SimpleDateFormatdateFormat=newSimpleDateFormat(strFormat);returndateFormat.format(now);}//弹出消息privatevoidopenToast(StringstrMsg){Toast.makeText(this,strMsg,Toast.LENGTH_LONG).show();}}你int类型的产量是不是传成字符串了??感觉是这个的问题 StringstrUrlPath="http://192.168.31.177:8081"+"DataTime="+strNowDateTime; 这8081后不需要跟/?吗?你把URL打印出来,应该是规范   还是不行把异常贴出来问题找到了是android4.0之后要在子线程里面访问网络但我不知道怎么用OkHttp,大神给个qq嘛帮我解决下问题嘛谢谢!!!太乱了,你要POST就POST,你的时间戳也别附加到url后面,当然如果你一定要这样,那也可以,我估计你的URL有问题,只是建议你,要么断点,要么2分法调试,你可以先把完整URL直接在浏览器里试一试看看,明显没有加问号

爱吃鱼的程序员 2020-06-08 15:40:08 0 浏览量 回答数 0
阿里云大学 云服务器ECS com域名 网站域名whois查询 开发者平台 小程序定制 小程序开发 国内短信套餐包 开发者技术与产品 云数据库 图像识别 开发者问答 阿里云建站 阿里云备案 云市场 万网 阿里云帮助文档 免费套餐 开发者工具 企业信息查询 小程序开发制作 视频内容分析 企业网站制作 视频集锦 代理记账服务 企业建站模板