public static string GetHttpResponse(string url)

{

string content = "";

// Create a new HttpWebRequest object.Make sure that

// a default proxy is set if you are behind a fure wall.

//其中,HttpWebRequest实例不使用HttpWebRequest的构造函数来创建,二是使用WebRequest的Create方法来创建.

HttpWebRequest myHttpWebRequest1 = (HttpWebRequest)WebRequest.Create(url);

//myHttpWebRequest1.Method = "POST";

//myHttpWebRequest1.ContentType = "application/x-www-form-urlencoded";

////不维持与服务器的请求状态

myHttpWebRequest1.KeepAlive = true;

//myHttpWebRequest1.AllowAutoRedirect = false;

//创建一个HttpWebRequest对象

//Assign the response object of HttpWebRequest to a HttpWebResponse variable.\

HttpWebResponse myHttpWebResponse1;

try

{

myHttpWebResponse1 = (HttpWebResponse)myHttpWebRequest1.GetResponse();

//设置页面的编码模式

//System.Text.Encoding utf8 = System.Text.Encoding.gb;

//System.Text.Encoding.GetEncoding("GB2312").GetString(System.Text.Encoding.UTF8.GetBytes("你的xml字符串"));

Stream streamResponse = myHttpWebResponse1.GetResponseStream();

StreamReader streamRead = new StreamReader(streamResponse, System.Text.Encoding.GetEncoding("GB2312"));

Char[] readBuff = new Char[256];

//这里使用了StreamReader的Read()方法,参数意指从0开始读取256个char到readByff中.

//Read()方法返回值为指定的字符串数组,当达到文件或流的末尾使,方法返回0

int count = streamRead.Read(readBuff, 0, 256);

while (count > 0)

{

String outputData = new String(readBuff, 0, count);

content += outputData;

count = streamRead.Read(readBuff, 0, 256);

}

myHttpWebResponse1.Close();

return content;

}

catch (WebException ex)

{

content = "在请求URL为:" + url.ToString() + " 的页面时产生错误,错误信息为" + ex.ToString();

return content;

}

}

public static IdentlyInfo CredentialsInfo(string identity, string userName)

{

IdentlyInfo identlyInfo = new IdentlyInfo();

string retStr = "";

string url = "http://172.168.254.34:9090/NCIIS/PersonInfoServlet?id=" + identity + "&name=" + userName + "";

//  strResult = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><data><status></status><id>身份证号码</id><name>姓名</name><photo>http://b.hiphotos.baidu.com/image/pic/item/f11f3a292df5e0fef825890b5e6034a85edf72fe.jpg</photo></data>";

string strResult = GetHttpResponse(url);

int start, end;

string statusCode = "<status>";

// string strorderstate = null;

start = strResult.LastIndexOf(statusCode) + statusCode.Length;

int starts = strResult.IndexOf("</status>");

if (start != -1)

{

identlyInfo.status = strResult.Substring(start, starts - start);

}

string id = "<id>";

//string strid = null;

start = strResult.LastIndexOf(id) + id.Length;

starts = strResult.IndexOf("</id>");

if (start != -1)

{

identlyInfo.id = strResult.Substring(start, starts - start);

}

string name = "<name>";

//string strname = null;

start = strResult.LastIndexOf(name) + name.Length;

starts = strResult.IndexOf("</name>");

if (start != -1)

{

identlyInfo.name = strResult.Substring(start, starts - start);

}

string photo = "<photo>";

//string strphoto = null;

start = strResult.LastIndexOf(photo) + photo.Length;

starts = strResult.IndexOf("</photo>");

if (start != -1)

{

identlyInfo.photo = strResult.Substring(start, starts - start);

}

if (identlyInfo.status != "00")

{

retStr = "身份证和姓名不匹配!";

}

else

{

retStr = identlyInfo.photo;

}

return identlyInfo;

}

根据URL请求 返回XML字符串的更多相关文章

  1. ajax请求返回json字符串/json对象 处理

    1. 返回json字符串如何处理 $.ajax({ url:xxx, success:function(date){ }, error:function(){ } }); 通过最原始的返回: Prin ...

  2. 【Spring MVC】spring mvc中相同的url请求返回不同的结果

    在项目中凡是使用Spring MVC这种控制器的,大多都是返回JSON数据对象,或者JSP页面. 但是相同的URL请求如何让他自动的选择放回的是什么? 在这里有由于鄙人没有亲自测试过,就不敢乱贴代码, ...

  3. c# 对SOAP返回XML字符串的解析方法

    <SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP:Head ...

  4. jsp Ajax请求(返回xml数据类型)

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  5. ajax请求返回Json字符串运用highcharts数据图表展现数据

    [1].[图片] Json字符串和highcharts数据图表展现.jpg 跳至 [1] code=26754#44745" rel="nofollow"> [2] ...

  6. .net 超长URL请求返回404错误-解决方法

    <system.webServer> <security> <requestFiltering> <requestLimits maxQueryString= ...

  7. url请求返回结果测试工具(CURL)

    官网:http://curl.haxx.se/download.html 具体用法用时百度 或  到时再补充

  8. springmvc返回json字符串中文乱码问题

    问题: 后台代码如下: @RequestMapping("menuTreeAjax") @ResponseBody /** * 根据parentMenuId获取菜单的树结构 * @ ...

  9. Asp.net mvc返回Xml结果,扩展Controller实现XmlResult以返回XML格式数据

    我们都知道Asp.net MVC自带的Action可以有多种类型,比如ActionResult,ContentResult,JsonResult……,但是很遗憾没有支持直接返回XML的XmlResul ...

随机推荐

  1. SQl查询数据库表名、表的列名、数据类型、主键

    1.获取所有数据库名:     2.Select Name FROM Master..SysDatabases order by Name   3.  4.2.获取所有表名:   5.   (1)  ...

  2. CentOS设置程序开机自启动的方法

    转自:http://www.centos.bz/2011/09/centos-setup-process-startup-boot/ 在CentOS系统下,主要有两种方法设置自己安装的程序开机启动. ...

  3. SVN各种错误提示产生原因及处理方法大全(转)

    SVN各种错误提示产生原因及处理方法大全 1. svn: Server sent unexpected return value (500 Internal Server Error) in resp ...

  4. shell脚本中多命令单行执行_转

    多命令一起执行 如果希望把几个命令合在一起执行, shell提供了两种方法.既可以在当前shell也可以在子shell中执行一组命令. 对{}和()而言, 括号中的重定向符只影响该条命令, 而括号外的 ...

  5. 创建动作action类:

    Action类是Struts 2应用程序的关键,我们实现了大部分Action类中的业务逻辑.因此,让我们创建一个Java文件HelloWorldAction.java的Java资源> SRC下一 ...

  6. makefile编写---:= ?= += =的区别

    在Makefile中我们经常看到 = := ?= +=这几个赋值运算符,那么他们有什么区别呢?我们来做个简单的实验 新建一个Makefile,内容为:ifdef DEFINE_VRE    VRE = ...

  7. 从获取点击事件根元素谈 target和currentTarget

    事情由来: 写了一个点击事件,想获取根元素,想的直接用current就行了,因为之前就是这么用的,但是之前的点击元素是没子元素的,current就是根元素,但是这次点击元素内部有子元素,current ...

  8. vim杂记

    "clang-completelet g:clang_complete_copen=1let g:clang_periodic_quickfix=1let g:clang_snippets= ...

  9. jQuery插件-json2.js

    from:http://blog.csdn.net/gjb724332682/article/details/46682743 前言 json2.js是一个json插件,下载地址:https://gi ...

  10. 持续集成 解决 Jenkins 中无法展示 HTML 样式的问题

    对于测试报告来说,除了内容的简洁精炼,样式的美观也很重要.常用的做法是,采用HTML格式的文档,并搭配CSS和JS,实现自定义的样式和动画效果(例如展开.折叠等). 在Jenkins中要展示HTML文 ...