Beginner Android Practice One

Source: Internet
Author: User

Before I learned C # and wanted to go to Android, it was a little white. Then I read some of Android's teaching videos and learned it in http://www.imooc.com/course/list.

Then want to do a login to the small dome, then I will start to pull interface, write event, write interface. Feel a good feeling in a moment (self-feeling just don't take it seriously, you big laughed at)

Then we say interface, interface I wrote it with WebService. There are two ways to

Method One: is based on the user name, password to get whether to actually put back a JSON format data,

Method Two: According to the name, fuzzy query data, return JSON format data.

Then the interface is written, and the client is set up, and the method of invoking the interface is written. How to call it. Then I went to see the HTTP-related protocols, methods, how to use. Because it's little white, I'm going to encode the code step-by-step in the video. Worry about the bug will be error, so it is very serious to check the relevant code. It was OK to start doing it right.

The result of the execution is error, the tracking debugging has been wrong prompt is 500. See is this error, decisive know is the server error. Then I checked my WebService service. The discovery service is able to access and get the correct data.

No problem was found, I started Baidu. Baidu Search results said: "See if the URL and parameters are passed in correctly." I then rejected the URL in the method and passed in the parameter.

because it is small white, so the results of the investigation did not find the problem where to travel. Then I began to think, because my webservice deployed on this machine, is not a LAN problem. not accessible via phone. Then I use the mobile phone connected to the WiFi (computer and mobile phone connected to the same), with the mobile phone test WebService interface can be normal access to the phone, test results: The phone can access the normal webservice.

I began to struggle with the test here. URL and parameters are passed in, local area network can be accessed, why the 500 error is reported.

After the early friend (abbreviation: II) to a network to access the URL and related parameters to test the method, see is not my method where there is wrong. Modified test to get data normally

Then I was strange, my URL and parameters are true, I can not access the success, and the II to my URL and parameters are normal access. I have a comparison of URL addresses

My url:http://192.168.100.147:8081/service1.asmx?op=getcusinfo.

Ii. url:http://117.29.161.210:8091/web/api/vehicle/getsignoutpassfeenew

Two URL addresses there's nothing wrong with that. There is no error in passing the parameter. It makes me more puzzled. Then started Baidu to find related issues. This time I think I used to get the data is not the right way (using HttpPost), and then found on Baidu on the Android call WebService post (http://www.cnblogs.com/gzggyy/archive/ 2011/06/21/2086140.html), he uses the method is soapobject this class carries on the related data the acquisition, inside has the correlation method the code. I'm not here to enumerate.

Although it can solve the problem of data acquisition, but I am still a bit tangled with Httpost way to get the data, for what (should I think the way to use the HttpPost code less to write it is also very convenient). Then I had to start the search.

Kung Fu is not a conscientious, I found a post in the method of the class capacity:

Discovery is what I want, I have a comparison of my relevant URLs, parameters. The URL looks different. Instant happy, then I changed my URL changed to: Http://192.168.100.147:8081/Service1.asmx/GetCusInfo such. But I was in the execution of the time still error. Then I put the URL into the browser to perform the discovery of a URL execution error. Then you use the URL address inside the post to access, the result is access to success. I was happy to find out where the problem was, and I made a change to the webservice. Discovery is supposed to be not configured for WebService

<webServices>
<protocols>
<add name= "HttpPost"/>
<add name= "HttpGet"/>
</protocols>
</webServices>

Add a <system.web> node inside the configuration file

After the configuration succeeds, the test applet access is successful. The related put back data is also obtained. But the result:

But the prefix, when I parse the JSON error, and then the search how to remove the prefix. Method One: Jsonstr.replaceall ("</?[ ^>]+> "," "). Trim () The string format Jsonstr execution method gets the pure JSON data. But in this way I feel a little dangling, always feeling wrong. Then the webservice was modified, but how should I change it.

Baidu also found the relevant issues, and then I changed the code:. The only data you get is that the data in pure JSON is not prefixed.

The small Program Data analysis show is also successful

Beginner Android Practice One

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.