android中的ksoap2异常处理(ksoap2 exception handling in android)
我在以下代码中遇到异常
package com.dipl.smpm.smpm; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapPrimitive; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.AndroidHttpTransport; import org.ksoap2.transport.HttpTransport; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import android.widget.Toast; public class ConnectHttp extends Activity { private static final String SOAP_ACTION = "http://tempuri.org/loginDetails"; private static final String METHOD_NAME = "loginDetails"; private static final String NAMESPACE = "http://tempuri.org/"; private static final String URL = "http://localhost:88/EmpService.asmx"; TextView tv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv=(TextView)findViewById(R.id.textView11); SoapObject sobj_requestLogin=new SoapObject(NAMESPACE, METHOD_NAME); sobj_requestLogin.addProperty("username", "a"); sobj_requestLogin.addProperty("password", "a"); SoapSerializationEnvelope spenve_Login = new SoapSerializationEnvelope(SoapEnvelope.VER11); spenve_Login.dotNet=true; spenve_Login.setOutputSoapObject(sobj_requestLogin); AndroidHttpTransport htrans_login= new AndroidHttpTransport(URL); try{ Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_SHORT).show(); htrans_login.call(SOAP_ACTION,spenve_Login); Toast.makeText(getApplicationContext(), "2", Toast.LENGTH_SHORT).show(); SoapPrimitive spprim_login=(SoapPrimitive)spenve_Login.getResponse(); Toast.makeText(getApplicationContext(), "3", Toast.LENGTH_SHORT).show(); tv.setText("result: "+spprim_login+" "); Toast.makeText(getApplicationContext(), "4", Toast.LENGTH_SHORT).show(); } catch(Exception e){ Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_LONG).show(); } } }
我成功地举杯祝酒,但是在吐司'2'来临之前,它会立刻进入'异常'吐司。 帮帮我,我的错误是什么? 我也使用2.3 ksoap2 2.3 jar作为用户定义的lib。
I'm getting exception in the following code
package com.dipl.smpm.smpm; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapPrimitive; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.AndroidHttpTransport; import org.ksoap2.transport.HttpTransport; import android.app.Activity; import android.os.Bundle; import android.widget.TextView; import android.widget.Toast; public class ConnectHttp extends Activity { private static final String SOAP_ACTION = "http://tempuri.org/loginDetails"; private static final String METHOD_NAME = "loginDetails"; private static final String NAMESPACE = "http://tempuri.org/"; private static final String URL = "http://localhost:88/EmpService.asmx"; TextView tv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv=(TextView)findViewById(R.id.textView11); SoapObject sobj_requestLogin=new SoapObject(NAMESPACE, METHOD_NAME); sobj_requestLogin.addProperty("username", "a"); sobj_requestLogin.addProperty("password", "a"); SoapSerializationEnvelope spenve_Login = new SoapSerializationEnvelope(SoapEnvelope.VER11); spenve_Login.dotNet=true; spenve_Login.setOutputSoapObject(sobj_requestLogin); AndroidHttpTransport htrans_login= new AndroidHttpTransport(URL); try{ Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_SHORT).show(); htrans_login.call(SOAP_ACTION,spenve_Login); Toast.makeText(getApplicationContext(), "2", Toast.LENGTH_SHORT).show(); SoapPrimitive spprim_login=(SoapPrimitive)spenve_Login.getResponse(); Toast.makeText(getApplicationContext(), "3", Toast.LENGTH_SHORT).show(); tv.setText("result: "+spprim_login+" "); Toast.makeText(getApplicationContext(), "4", Toast.LENGTH_SHORT).show(); } catch(Exception e){ Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_LONG).show(); } } }
i'm getting a toast '1' sucessfully but its going to 'exception' toast immediately before toast '2' comes. help me what is my mistake? also i'm using 2.3 ksoap2 2.3 jar as user defined lib.
原文:https://stackoverflow.com/questions/17448036
最满意答案
如上所述,您无需将配置文件URL保存到数据库。 我猜所有的个人资料网址都会遵循一些标准格式(即
www.example.com/profile.php?id=1
)?好吧,如果您保存了数据库中的所有内容,然后您决定将格式更改为类似于
www.example.com/profile/1
那么您将拥有大量过时的数据。你的数据库。 您将不得不浏览每条记录并更新它,这对数据库表来说可能是危险的,比如数百万行。因此,解决方案是使用带参数的脚本。 说
profile.php
。 如上所述,您将使用$_GET
数组中的数据检查配置文件:<?php if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $sql = "SELECT * FROM members WHERE id = '$id' LIMIT 1"; $res = mysql_query($sql); if (mysql_num_rows() > 0) { $member = mysql_fetch_object($res); // handle displaying of member's profile here } else { // member does not exist with ID } } ?>
这样,如果您决定更改脚本名称或使用搜索引擎友好的URL,则无需更改数据库结构。
As stated above, you don't need to save a profile URL to the database. I'm guessing all profile URLs are going to follow some standard form (i.e.
www.example.com/profile.php?id=1
)?Well, if you saved all of those in your database and then you decided you were going to change the format to something like
www.example.com/profile/1
you're going to have a lot of out-of-date data in your database. You're going to have to go through each record and update it, and that could be dangerous on a database table with say, millions of rows.Therefore, the solution is to have a script that takes a parameter. Say
profile.php
. As above, you would check for the profile using the data in the$_GET
array:<?php if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $sql = "SELECT * FROM members WHERE id = '$id' LIMIT 1"; $res = mysql_query($sql); if (mysql_num_rows() > 0) { $member = mysql_fetch_object($res); // handle displaying of member's profile here } else { // member does not exist with ID } } ?>
That way, if you decide to change the script name or use search engine-friendly URLs, you don't need to change your database structure.
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
我们将此设置与我们的一些应用程序一起使用 - User - > Profile 。 简而言之,您应该在用户创建时构建配置文件。 然后,您可以根据需要编辑配置文件。 你有一个Profile.new方法的问题是非常低效的... #app/models/user.rb class User < ActiveRecord::Base has_one :profile before_create :build_profile #-> saves blank associated "Profile" ob ...
-
为每个用户配置文件创建唯一URL的最佳做法是什么(What is the best practice to create a unique url for every user profile)[2024-01-08]
保持用户体验,首先为用户提供唯一的ID,通过它您可以轻松识别用户。 之后,您可以允许用户选择任何新的用户名(屏幕名称),但应再次检查用户名是否必须再次唯一。 取决于您的要求。 请告诉我们您最后选择的方式。 Keeping in the User experience in consideration, firstly provide the user with unique id, through which you can identify the User easily. After that you ... -
假设您有一个UserController,并且您要将任何domain.com/username映射到用户控制器的show动作,您的URL映射可能是这样的:在我的示例中,name将成为params中的参数。 有关详细信息,请参阅此处 希望这可以帮助。 static mappings = { "/$name"(controller: "user", action: "show") ... } Assuming you have a UserController and you are goi ...
-
如上所述,您无需将配置文件URL保存到数据库。 我猜所有的个人资料网址都会遵循一些标准格式(即www.example.com/profile.php?id=1 )? 好吧,如果您保存了数据库中的所有内容,然后您决定将格式更改为类似于www.example.com/profile/1那么您将拥有大量过时的数据。你的数据库。 您将不得不浏览每条记录并更新它,这对数据库表来说可能是危险的,比如数百万行。 因此,解决方案是使用带参数的脚本。 说profile.php 。 如上所述,您将使用$_GET数组中的数据检查 ...
-
这将是您的重定向URL的正确正则表达式,即。 不要修改你拥有的那个。 url(r'^profile/(?P
\w+)/$', 'pet.views.myprofileview', name="detail_profile") 然后将参数传递给重定向: url = reverse('detail_profile', kwargs={'username': profile.firstname}) return HttpResponseRedirect(url) 这导致还必须定义新视图: d ... -
RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^//]+)$ user.php?id=$1 [QSA,L] 这将排除现有文件。 RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^//]+)$ user.php?id=$1 [QSA,L] That wil ...
-
使用request.user而不是url中的id生成用户配置文件(Generating user profiles with request.user rather than id in url)[2021-07-24]
首先,如果您不在URL中使用其ID来生成视图,您将永远无法查看其他用户配置文件。 但是,没有理由通过这种方式设计用户配置文件,从而产生速度等负面影响。 我个人会建议反对它,因为它会限制用户配置文件可以实现的功能。 在安全性方面,您可以在用户配置文件视图周围添加一个检查,以检查当前用户是否有权访问。 Firstly, you will never be able to view another users profile if you do not use their ID in the URL to gen ... -
如何在Django请求上发送JSON以创建新的用户和配置文件?(How I can send JSON on Django request to create a new User and Profile?)[2021-12-15]
我认为可能缺乏对User模型的引用。 假设您的Profile模型如下所示: class Profile(models.Model): user = models.ForeignKey(User) 模型User将具有profile_set属性而不是profile 。 要调整此项,请使用related_name : class Profile(models.Model): user = models.OneToOneField(User, related_name='profile') I ...