SOAP Protocol

SOAP – Simple object access protocol, based on the HTTP, using in the information transferring between endpoints on the Internet.
SOAP – 简单对象存取协议,基于HTTP,是一个用来在Internet上传输信息的标准

SOAP package from sender (发送方的例子)

The package from sender in like below:
发送方的代码如下:

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Header>
  ...
  ...
</soap:Header>

<soap:Body>
  ...
  ...
  <soap:Fault>
    ...
    ...
  </soap:Fault>
</soap:Body>

</soap:Envelope>

The namespaces and the Envelope in the example are forced to be present. the Header is optional.
其中命名空间和Envelop标签都是必须的,Header标签是可选的。
In the Body, the sender can have what ever it want to be there, but must follow the XML rules.
在Body标签中,应用程序可以放入其需要传输的任何内容。

The response from receiver (接收方的反馈)

<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">

<soap:Body>
   <m:GetPriceResponse xmlns:m="http://www.w3school.com.cn/prices">
      <m:Price>1.90</m:Price>
   </m:GetPriceResponse>
</soap:Body>

</soap:Envelope>

In this manner, the endpoints exchange informations through internet.
终端之间就是通过这种简单的方式进行数据传输的。

Using in Ruby – SOAP4R (Ruby中的gem – SOAP4R)

http://www.tutorialspoint.com/ruby/ruby_web_services.htm

Reference (参考)

http://w3school.com.cn/soap/index.asp

从短url获取正常url(php,objective-c ios)

微博的兴起将很多长的url转换成了短url地址,但是有时候我们需要先通过短url拿到长url,再进行进一步的处理。

ios方法

  1. +(NSString*)unshortUrl🙁NSString*)shortUrl{
  2.     shortUrl = @“http://rrurl.cn/xxoo”;
  3.     NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:shortUrl]];
  4.     NSHTTPURLResponse *response = [[[NSHTTPURLResponse alloc] init] autorelease];
  5.     [NSURLConnection sendSynchronousRequest:request returningResponse:>response error:nil];
  6.     return response.URL.absoluteString;
  7. }

php方法

  1. $url = “http://rrurl.cn/xxoo”; 
  2. echo unshorten($url); 
  3. function unshorten($url) { 
  4. $url = trim($url); 
  5. $headers = get_headers($url); 
  6. $location = $url; 
  7. $short = false; 
  8. foreach($headers as $head) { 
  9. if($head==“HTTP/1.1 302 Found”) $short = true; 
  10. if($short >> startwith($head,“Location: “)) { 
  11. $location = substr($head,10); 
  12. } 
  13. } 
  14. return $location; 
  15. } 

第一次写Apache2的RewriteRule(用于域名泛解析)

在研究了正则表达式和apache的rewrite模块之后,写了第一个rewriterule,实现的功能是:
将所有的对:
name1.name2.dom.com/someResource
的访问都定向到服务器目录:
/server/name2/name1/someResource
其中name1和someResource是可变部分。对于name1,相当于实现了三级域名的泛解析。

那么在VirtualHost块下是这么写的:
//打开重写模块,这个的好处在于不需要重写的的时候,只把on改成off就让下面的代码全部失效了,不用一句一句注释
RewriteEngine on
//判断继续下一步的条件是请求的url的服务器部分(http://之后到第一个/之前,变量名是%{HTTP_HOST})
//是不是长得像name1.name2.dom.com

RewriteCond %{HTTP_HOST} ^[^.]+.name2.dom.com$
//重写访问的地址,将"/someResource"改为:"name1.name2.dom.com/someResource"
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
//再重写一次,将"name1.name2.dom.com/someResource",改写为"/server/name2/name1/someResource"
//其中每个()匹配的字符串都可以用$1这样的变量名来引用,()的定义是从左到右编号的(从1开始)
//第一个()是:([^.]+),在这里匹配的是"name1"字符串,也就相当于$1="name1"
//第二个()是:(.),在这里匹配的是"/someSource",也就相当于$2="/someSource"
//所以重写的结果"/server/name2/$1$2"翻译出来就是"/server/name2/name1/someSource"。也就是我们的目标地址

RewriteRule ^([^.]+).name2.dom.com(.
) /server/name2/$1$2

正则表达式

想学正则表达式很久了,今天终于看了看。因为在apache中的rewrite中需要用正则表达式去匹配url。
后面链接的一篇文章讲得很详细了,就不复制粘贴了,以后有学习心得之类的再补充在此。

一篇好文章可以看看:
http://manual.phpv.net/regular_expression.htmlX50X
另外一个来自百度百科的条目,其中有正则表达式各个字符的含义
正则表达式字符含义在此

在objective-c中使用的方式如下:(这个例子检测文本text中的url)

  1.     NSString *text = [info objectForKey:@“text”];
  2.     NSString *urlDetected = nil;
  3.     {//url detection
  4.         //if there is a link of this feed, such as video share, the text is like:@”sometexthttp://somelocation”. And the url link is only contained in this text.
  5.         NSRegularExpression *regExp = [NSRegularExpression regularExpressionWithPattern:@“(http|https|ftp)\\://([a-zA-Z0-9\\.\\-]+(\\:[a-zA-Z0-9\\.>amp;%\\$\\-]+)*@)?((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0-9\\-]+\\.)*[a-zA-Z0-9\\-]+\\.[a-zA-Z]{2,4})(\\:[0-9]+)?(/[^/][a-zA-Z0-9\\.\\,\\?\\’\\\\/\\+>amp;%\\$#\\=~_\\-@]*)*” options:NSRegularExpressionCaseInsensitive error:nil];
  6.         NSRange matchedUrlRange = [regExp rangeOfFirstMatchInString:text options:0 range:NSMakeRange(0, text.length)];
  7.         if (matchedUrlRange.location != NSNotFound) {
  8.             urlDetected = [text substringWithRange:matchedUrlRange];
  9.         }
  10.     }

http中content-type对照表【转】

常见文件的http中content-type头的值(MIME类型)

An official listing of defined MIME types:

.ai - application/postscript
.aif - audio/x-aiff
.aifc - audio/x-aiff
.aiff - audio/x-aiff
.asc - text/plain
.au - audio/basic
.avi - video/x-msvideo
.bcpio - application/x-bcpio
.bin - application/octet-stream
.c - text/plain
.cc - text/plain
.ccad - application/clariscad
.cdf - application/x-netcdf
.class - application/octet-stream
.cpio - application/x-cpio
.cpt - application/mac-compactpro
.csh - application/x-csh
.css - text/css
.dcr - application/x-director
.dir - application/x-director
.dms - application/octet-stream
.doc - application/msword
.drw - application/drafting
.dvi - application/x-dvi
.dwg - application/acad
.dxf - application/dxf
.dxr - application/x-director
.eps - application/postscript
.etx - text/x-setext
.exe - application/octet-stream
.ez - application/andrew-inset
.f - text/plain
.f90 - text/plain
.fli - video/x-fli
.gif - image/gif
.gtar - application/x-gtar
.gz - application/x-gzip
.h - text/plain
.hdf - application/x-hdf
.hh - text/plain
.hqx - application/mac-binhex40
.htm - text/html
.html - text/html
.ice - x-conference/x-cooltalk
.ief - image/ief
.iges - model/iges
.igs - model/iges
.ips - application/x-ipscript
.ipx - application/x-ipix
.jpe - image/jpeg
.jpeg - image/jpeg
.jpg - image/jpeg
.js - application/x-javascript
.kar - audio/midi
.latex - application/x-latex
.lha - application/octet-stream
.lsp - application/x-lisp
.lzh - application/octet-stream
.m - text/plain
.man - application/x-troff-man
.me - application/x-troff-me
.mesh - model/mesh
.mid - audio/midi
.midi - audio/midi
.mif - application/vnd.mif
.mime - www/mime
.mov - video/quicktime
.movie - video/x-sgi-movie
.mp2 - audio/mpeg
.mp3 - audio/mpeg
.mpe - video/mpeg
.mpeg - video/mpeg
.mpg - video/mpeg
.mpga - audio/mpeg
.ms - application/x-troff-ms
.msh - model/mesh
.nc - application/x-netcdf
.oda - application/oda
.pbm - image/x-portable-bitmap
.pdb - chemical/x-pdb
.pdf - application/pdf
.pgm - image/x-portable-graymap
.pgn - application/x-chess-pgn
.png - image/png
.pnm - image/x-portable-anymap
.pot - application/mspowerpoint
.ppm - image/x-portable-pixmap
.pps - application/mspowerpoint
.ppt - application/mspowerpoint
.ppz - application/mspowerpoint
.pre - application/x-freelance
.prt - application/pro_eng
.ps - application/postscript
.qt - video/quicktime
.ra - audio/x-realaudio
.ram - audio/x-pn-realaudio
.ras - image/cmu-raster
.rgb - image/x-rgb
.rm - audio/x-pn-realaudio
.roff - application/x-troff
.rpm - audio/x-pn-realaudio-plugin
.rtf - text/rtf
.rtx - text/richtext
.scm - application/x-lotusscreencam
.set - application/set
.sgm - text/sgml
.sgml - text/sgml
.sh - application/x-sh
.shar - application/x-shar
.silo - model/mesh
.sit - application/x-stuffit
.skd - application/x-koan
.skm - application/x-koan
.skp - application/x-koan
.skt - application/x-koan
.smi - application/smil
.smil - application/smil
.snd - audio/basic
.sol - application/solids
.spl - application/x-futuresplash
.src - application/x-wais-source
.step - application/STEP
.stl - application/SLA
.stp - application/STEP
.sv4cpio - application/x-sv4cpio
.sv4crc - application/x-sv4crc
.swf - application/x-shockwave-flash
.t - application/x-troff
.tar - application/x-tar
.tcl - application/x-tcl
.tex - application/x-tex
.texi - application/x-texinfo
.texinfo - application/x-texinfo
.tif - image/tiff
.tiff - image/tiff
.tr - application/x-troff
.tsi - audio/TSP-audio
.tsp - application/dsptype
.tsv - text/tab-separated-values
.txt - text/plain
.unv - application/i-deas
.ustar - application/x-ustar
.vcd - application/x-cdlink
.vda - application/vda
.viv - video/vnd.vivo
.vivo - video/vnd.vivo
.vrml - model/vrml
.wav - audio/x-wav
.wrl - model/vrml
.xbm - image/x-xbitmap
.xlc - application/vnd.ms-excel
.xll - application/vnd.ms-excel
.xlm - application/vnd.ms-excel
.xls - application/vnd.ms-excel
.xlw - application/vnd.ms-excel
.xml - text/xml
.xpm - image/x-xpixmap
.xwd - image/x-xwindowdump
.xyz - chemical/x-pdb
.zip - application/zip