待解析字符串
String content = "pageindex=2&articleId=23462041";
代码
package com.basic;
import java.util.HashMap;
public class Parse03 {
public static void main(String[] args) {
String post = "POST http://120.132.0.117:8080/yun90/article/GetRelatedArticles HTTP/1.1\r\nHost: blog.csdn.net\r\nConnection: keep-alive\r\n\r\npageindex=2&articleId=23462041";
String content = "pageindex=2&articleId=23462041";
System.out.println(content);
/*
* 一、将键值对存入HashMap
*/
HashMap<String, String> contentMap = new HashMap<String, String>();
String[] arry1 = content.split("&");
for (int i = 0; i < arry1.length; i++) {
String[] arry2 = arry1[i].split("=");
contentMap.put(arry2[0], arry2[1]);
}
System.out.println("---------------------取数据-------------------");
String articleId = contentMap.get("articleId");
System.out.println("articleId=" + articleId);
}
}
待解析字符串
String heads = "Host: blog.csdn.net\r\nConnection: keep-alive";
代码
package com.basic;
import java.util.HashMap;
public class Parse04 {
public static void main(String[] args) {
String post = "POST http://120.132.0.117:8080/yun90/article/GetRelatedArticles HTTP/1.1\r\nHost: blog.csdn.net\r\nConnection: keep-alive\r\n\r\npageindex=2&articleId=23462041";
/*
* 一、将键值对存入HashMap
*/
String heads = "Host: blog.csdn.net\r\nConnection: keep-alive";
System.out.println(heads);
HashMap<String, String> headsMap = new HashMap<String, String>();
String[] arry3 = heads.split("\r\n");
for (int i = 0; i < arry3.length; i++) {
String[] arry4 = arry3[i].split(":");
headsMap.put(arry4[0], arry4[1]);
}
System.out.println("---------------------取数据-------------------");
String host = headsMap.get("Host");
System.out.println("host=" + host);
}
}