gpt4 book ai didi

android - 在同一 Activity 中调用 Web 服务中的两种方法会出现异常

转载 作者:行者123 更新时间:2023-11-29 02:09:20 25 4
gpt4 key购买 nike

我在同一 Activity 中调用两个网络服务时遇到了一个奇怪的问题。当我一个接一个地调用 Web 服务的两种方法时,给了我一个异常(exception)。一切都是正确的,我不知道问题所在。有人遇到过这个问题吗?请给我一些建议...

这是调用网络服务的代码:

   public static String getRelatedVideoResponse(String request, String url,
String action, String method, String namespace, String value) {
try {
System.setProperty("http.keepAlive", "false");

URL u = new URL(url);

URLConnection uc = u.openConnection();
HttpURLConnection connection = (HttpURLConnection) uc;

connection.setRequestProperty("connection", "close");

connection.setUseCaches(false);
connection.setConnectTimeout(30000);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestProperty("SOAPAction", action);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type",
"text/xml;charset=UTF-8");

OutputStream out = connection.getOutputStream();

Writer wout = new OutputStreamWriter(out);

wout.write(request);

wout.flush();


wout.close();
Log.e("before buffer","buffer");

BufferedReader rd = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
Log.e("buffer",rd+"");
Log.e("code...", connection.getResponseCode() + "");

while ((StaticUtils.sRelResult = rd.readLine()) != null) {

Log.e("result", StaticUtils.sRelResult);
return StaticUtils.sRelResult;
}

} catch (MalformedURLException e) {

e.printStackTrace();
} catch (IOException e) {
Log.e("error occured", "here");
e.printStackTrace();
}
return StaticUtils.sRelResult;
}

Activity :

    protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.searchvideos);
mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
switch (msg.what) {
case SUCCESS:
s = "<tns:int xmlns:tns=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">";
t = "</tns:int>";
buffer.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
buffer.append("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns=\"http://tempuri.org/\">");
buffer.append("<soap:Body><GetScoresForVideos><videoIDs>");
for (int i = 0; i < StaticUtils.sAlRelId.size(); i++) {
buffer.append(s + StaticUtils.sAlRelId.get(i) + t);
}
buffer.append("</videoIDs>");
buffer.append("</GetScoresForVideos></soap:Body></soap:Envelope>");
Log.e("bufer string", buffer.toString());
WsdlService s = new WsdlService();

s.getRelatedVideoResponse(buffer.toString(),
StaticUtils.URL, StaticUtils.RATE_ACTION,
StaticUtils.RATE_METHOD, StaticUtils.NAMESPACE, "");
break;
}
};

download();
}
private void download() {
Runnable r = new Runnable() {

public void run() {
if (StaticUtils.checkNetworkStatus(getApplicationContext()) == true) {
WsdlService service = new WsdlService(
StaticUtils.NAMESPACE,
StaticUtils.RELATED_METHOD_NAME, StaticUtils.URL,
StaticUtils.RELATED_SOAP_ACTION);
String str = service.getResponseById(Integer
.valueOf(videoId));

Log.e("Related videos", str);
RelatedParser parser = new RelatedParser(str);
parser.parseRelatedVideos();
onSuccessDownload();
} else {
onFailureDownload();
}

}
};
Thread t = new Thread(r);
t.start();

}
public void onSuccessDownload() {
mHandler.sendEmptyMessage(SUCCESS);
}

异常(exception)是:

12-05 14:55:11.604: WARN/System.err(3075): java.io.FileNotFoundException: http://192.80.62:48080/Services/v0.2.2/SampleService.svc?wsdl
12-05 14:55:11.613: WARN/System.err(3075): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:1162)
12-05 14:55:11.613: WARN/System.err(3075): at com.utils.WsdlService.getRelatedVideoResponse(WsdlService.java:180)
12-05 14:55:11.613: WARN/System.err(3075): at com.scopra.screens.RelatedVideos$2.handleMessage(RelatedVideos.java:146)
12-05 14:55:11.613: WARN/System.err(3075): at android.os.Handler.dispatchMessage(Handler.java:99)
12-05 14:55:11.613: WARN/System.err(3075): at android.os.Looper.loop(Looper.java:123)
12-05 14:55:11.613: WARN/System.err(3075): at android.app.ActivityThread.main(ActivityThread.java:4627)
12-05 14:55:11.613: WARN/System.err(3075): at java.lang.reflect.Method.invokeNative(Native Method)
12-05 14:55:11.613: WARN/System.err(3075): at java.lang.reflect.Method.invoke(Method.java:521)
12-05 14:55:11.613: WARN/System.err(3075): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-05 14:55:11.623: WARN/System.err(3075): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-05 14:55:11.623: WARN/System.err(3075): at dalvik.system.NativeStart.main(Native Method)

谢谢,

最佳答案

java.io.FileNotFoundException:http://192.80.62:48080/Services/v0.2.2/SampleService.svc?wsdl

仔细看,IP地址好像拼错了。您可能需要将其更改为 192.80.62.4:8080?

关于android - 在同一 Activity 中调用 Web 服务中的两种方法会出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8383290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com