C # fetching Java interfaces

Source: Internet
Author: User

1.

public class Apirequest
{
public static string commonurl = @ "http://192.168.2.186:8080/sale/";
public static string commonurl = @ "http://115.29.102.31:9011/sale/";

#region Generic API Requests
<summary>
Common API Requests
</summary>
<param name= "ServerURL" ></param>
<param name= "Paramjsonstr" ></param>
<returns></returns>
public static string Commonapiaccess (String ServerURL, byte[] bytearr)
{
String strresult = "";
Try
{
HttpWebRequest commonrequest = (HttpWebRequest) webrequest.create (ServerURL);
Commonrequest.method = "POST";

Commonrequest.contenttype = "Application/x-json";
byte[] Bytearr = Encoding.UTF8.GetBytes (param);
using (Stream Reqstream = Commonrequest.getrequeststream ())
{
Reqstream.write (Bytearr, 0, bytearr.length);
}
using (HttpWebResponse Httpwresp = (HttpWebResponse) commonrequest.getresponse ())
{
Try
{
Stream MyStream = Httpwresp.getresponsestream ();
StreamReader sr = new StreamReader (MyStream, Encoding.UTF8);
StringBuilder Strbuilder = new StringBuilder ();
while ( -1! = Sr. Peek ())
{
Strbuilder.append (Sr. ReadLine ());
}
strresult = Httputility.urldecode (strbuilder.tostring ());
}
catch (Exception exp)
{
strresult = "400";//"Error:" + exp. Message;
}
}
}
catch (Exception exp)
{
strresult = "500";//"Error:" + exp. Message;
}
return strresult;
}

#endregion

}

2. Invoking an instance

String json = apirequest.commonapiaccess (Apirequest.commonurl + "Icity.do?m=getcitybyprovinceid", Encoding.UTF8.GetBytes (Httputility.urlencode ("{\" code\ ": \" "+ comprovince. Selectedvalue.tostring () + "\"} ", Encoding.UTF8));
String msg = "1";
if (json! = "500")
{
Try
{

list<city> list = jsonconvert.deserializeobject<list<city>> (JSON);
Comcity. DataSource = list;
Comcity. DisplayMember = "name";
Comcity. ValueMember = "code";
}
catch (Exception ex)
{
msg = "400";
}
}
Else
{MessageBox.Show ("Connection to Server failed");}

C # fetching Java interfaces

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.