C/C++对URL分割进行实现
来源:互联网 发布:网络cry是什么意思啊 编辑:程序博客网 时间:2024/06/08 07:23
分割URL,并提取其参数值
例如:http://download.pchome.net/php/tdownload2.php?sid=18377&url=/system/patch/srsp1.exe&svr=2&typ=0
例如:http://download.pchome.net/php/tdownload2.php?sid=18377&url=/system/patch/srsp1.exe&svr=2&typ=0
- C/C++ code
#include <stdio.h>#include <string.h>#include <stdlib.h>char sU[]="http://***.***.***user_login_qp.php?uid=%BF%BC%C0%AD&pwd=7faac35ae7dcaddca9ef0c1b1c50e68a&flag=Test";char *getUrlParam(char *sUrl,char *sParam) { char s[1024],*p,a[80]; int L,n,k; static char v[80];v[0]=0; p=strchr(sUrl,'?'); if (!p) return v; strncpy(s,p,1023);s[1023]=0; s[0]='&'; a[0]='&'; strncpy(a+1,sParam,77);a[78]=0; strcat(a,"="); L=strlen(a); p=strstr(s,a); if (!p) return v; p=p+L; n=0; while (1) { if (p[n]=='&') {p[n]=0;break;} if (p[n]==0) break; if (n>=79) {p[n]=0;break;} n++; } if (n>0) { strcpy(a,p); L=0; p=a; while (1) { k=sscanf(p,"%%%2x",&n); if (1==k) { v[L++]=(char)n; p+=3; } else if (0==k) { v[L++]=p[0]; p++; } else break; } v[L]=0; } return v;}int main() { printf("uid=%s\n",getUrlParam(sU,"uid")); printf("pwd=%s\n",getUrlParam(sU,"pwd")); printf("flag=%s\n",getUrlParam(sU,"flag")); return 0;}//uid=考拉//pwd=7faac35ae7dcaddca9ef0c1b1c50e68a//flag=TestC++实现//主要用一个string拆分函数就可以了,其他你自己就可以拆分了。#include "stdafx.h"#include <vector>#include <string>using namespace std;vector<string> myStrsplit(string str, string separator);int _tmain(int argc, _TCHAR* argv[]){ string testdata="http://download.pchome.net/php/tdownload2.php?sid=18377&url=/system/patch/srsp1.exe&svr=2&typ=0"; vector<string> questiondata; questiondata=myStrsplit(testdata,"?"); vector<string> anddata; int count1=questiondata.size(); vector<string>::iterator ite; string mainurl = questiondata[0]; string cna=questiondata[1]; return 0;}vector<string> myStrsplit(string str, string separator) { vector<string> result; int cutAt; while( (cutAt = str.find_first_of(separator)) != str.npos ) { if(cutAt > 0) { result.push_back(str.substr(0, cutAt)); } str = str.substr(cutAt + 1); } if(str.length() > 0) { result.push_back(str); } return result; }
阅读全文
0 0
- C/C++对URL分割进行实现
- C语言 对字符串进行分割
- Objective-C 对 URL 进行 URLEncode 编码
- Objective-C 对URL进行URLEncode编码
- Objective-C 对 URL 进行 URLEncode 编码
- Objective-C 对 URL 进行 URLEncode 编码
- Objective-C 对 URL 进行 URLEncode 编码
- Objective-C 对 URL 进行 URLEncode 编码
- Objective-C 对 URL 进行 URLEncode 编码
- Objective-C 对 URL 进行 URLEncode 编码
- Objective-C 对 URL 进行 URLEncode 编码
- Objective-C 对 URL 进行 URLEncode 编码
- Objective-C 对 URL 进行 URLEncode 编码
- Objective-C 对 URL 进行 URLEncode 编码
- Objective-C 对 URL 进行 URLEncode 编码
- Objective-C 对 URL 进行 URLEncode 编码
- Objective-C 对 URL 进行 URLEncode 编码
- Objective-C 对 URL 进行 URLEncode 编码
- ionic 输入框
- contos7.0 jdk1.8 安装
- 利用百度云m3u8格式hls直播实例
- 100 个 Linux 常用命令大全
- GitHub访问不了
- C/C++对URL分割进行实现
- elasticsearch-jdbc同步myslq数据到elasticsearch
- python: hasattr()、setattr()、getattr()、delattr() 内建函数
- Linux常用的命令
- 手机访问PC网站自动跳转到手机网站代码
- Springboot从易到难(基本页面显示到框架整合、数据交互)
- spring mvc rocketMq简单配置
- 怎样根据使用环境需求来选择不同参数的光模块
- 国庆假期微信大数据报告