msgbartop
msgbarbottom

23 四 09 编写ASP uc-client与UC通信时遇到Access denied for agent changed

最近研究ASP 和康盛UCENTER通信,遇到了新的问题,

那就是在写uc_user_login等client端函数时 遇到 Access denied for agent changed 问题。

原因在于之前对UC与应用程序之间通信的校验原理没搞清楚的原因

故写博客备忘:

表忘记在http头提交需要的东东。

UC/model/base.php 中校验的http_user_agent是在模拟提交的过程中的当前客户浏览器的usera gent ,

如果在模拟提交过程中,没有将当前用户的useragent提交上去的话,那么UC在

uc/model/base.php 中的 init_input方法获取到的http_user_agent将会是应用服务器当前系统的默认user agent,

而不是客户端的http_user_agent,从而导致 http_user_agent 校验失败,而无法正常通信。

 

以下是PHP和ASP模拟提交的代码 

PHP代码
  1. function uc_fopen($url$limit = 0, $post = $cookie = $bysocket = FALSE, $ip = $timeout = 15, $block = TRUE) {   
  2.     $return = ;   
  3.     $matches = parse_url($url);   
  4.     !isset($matches['host']) && $matches['host'] = ;   
  5.     !isset($matches['path']) && $matches['path'] = ;   
  6.     !isset($matches['query']) && $matches['query'] = ;   
  7.     !isset($matches['port']) && $matches['port'] = ;   
  8.     $host = $matches['host'];   
  9.     $path = $matches['path'] ? $matches['path'].($matches['query'] ? ‘?’.$matches['query'] : ) : ‘/’;   
  10.     $port = !emptyempty($matches['port']) ? $matches['port'] : 80;   
  11.     if($post) {   
  12.         $out = “POST $path HTTP/1.0\r\n”;   
  13.         $out .= “Accept: */*\r\n”;   
  14.         //$out .= ”Referer: $boardurl\r\n”;   
  15.         $out .= “Accept-Language: zh-cn\r\n”;   
  16.         $out .= “Content-Type: application/x-www-form-urlencoded\r\n”;   
  17.         $out .= “User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n”;   
  18.         $out .= “Host: $host\r\n”;   
  19.         $out .= ‘Content-Length: ’.strlen($post).“\r\n”;   
  20.         $out .= “Connection: Close\r\n”;   
  21.         $out .= “Cache-Control: no-cache\r\n”;   
  22.         $out .= “Cookie: $cookie\r\n\r\n”;   
  23.         $out .= $post;   
  24.     } else {   
  25.         $out = “GET $path HTTP/1.0\r\n”;   
  26.         $out .= “Accept: */*\r\n”;   
  27.         //$out .= ”Referer: $boardurl\r\n”;   
  28.         $out .= “Accept-Language: zh-cn\r\n”;   
  29.         $out .= “User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n”;   
  30.         $out .= “Host: $host\r\n”;   
  31.         $out .= “Connection: Close\r\n”;   
  32.         $out .= “Cookie: $cookie\r\n\r\n”;   
  33.     }   
  34.     $fp = @fsockopen(($ip ? $ip : $host), $port$errno$errstr$timeout);   
  35.     if(!$fp) {   
  36.         return ;   
  37.     } else {   
  38.         stream_set_blocking($fp$block);   
  39.         stream_set_timeout($fp$timeout);   
  40.         @fwrite($fp$out);   
  41.         $status = stream_get_meta_data($fp);   
  42.         if(!$status['timed_out']) {   
  43.             while (!feof($fp)) {   
  44.                 if(($header = @fgets($fp)) && ($header == “\r\n” ||  $header == “\n”)) {   
  45.                     break;   
  46.                 }   
  47.             }   
  48.   
  49.             $stop = false;   
  50.             while(!feof($fp) && !$stop) {   
  51.                 $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));   
  52.                 $return .= $data;   
  53.                 if($limit) {   
  54.                     $limit -= strlen($data);   
  55.                     $stop = $limit <= 0;   
  56.                 }   
  57.             }   
  58.         }   
  59.         @fclose($fp);   
  60.         return $return;   
  61.     }   
  62. }  

因此,在ASP提交的时候也应该把这些头提交上去

 

ASP代码
  1. Private Function doPost(url,param)   
  2.     Dim https   
  3.     Set https = Server.CreateObject(“MSXML2.XMLHTTP”)    
  4.     https.Open “Post”, url, False  
  5.     useragent=http_user_agent()   
  6.     https.setRequestHeader “Accept”“*/*”  
  7.     https.setRequestHeader “Accept-Language”,“zh-cn”  
  8.     https.setRequestHeader “Content-Type”,“application/x-www-form-urlencoded”  
  9.     https.setRequestHeader “User-Agent”, useragent   
  10.     https.setRequestHeader “Content-Length”,len(param)   
  11.     https.setRequestHeader “Connection”,“Close”  
  12.     https.setRequestHeader “Cache-Control”,“no-cache”  
  13.     https.Send param   
  14.     If https.readystate=4 Then   
  15.         doPost = https.ResponseBody   
  16.         doPost = BytesToBstr(doPost,UC_CHARSET)   
  17.     End If   
  18.     Set https = Nothing    
  19. End Function   

如果不提交上去,特别是user agent如果不提交上去,肯定就会出现:Access denied for agent changed 错误

Tags: ,

20 四 08 Linux操作系统中关于负载的定义

使用uptime或者top命令,都可以看到一个负载的输出,形如load average: 0.00, 0.03, 0.00,这个负载到底是什么东西呢,man文档里只是一笔带过,没有具体的给出负载的定义。

  负载的统计,必然是由内核完成的,因此在内核源码中找答案是再好不过的事情了,找来2.6.21的内核源码,开始探索。 (全文 …)

Tags:

10 四 08 十个习惯让你精通新的开发技术

Ben Watson,知名开发者。任职于GeoEye,是其所属开发团队的领导者。本文发表于他自己的博客,阐述了十种学习新技术的方法。

这篇文章,是从我的《高效开发人员的五个特征》一文中抽出的一个观点。从我自身的事业和习惯中,我考虑了很多方式怎么样才能有效地学习。 (全文 …)

27 三 08 在Zend Studio for Eclipse 6中自动换行

Zend Studio for Eclipse 6用了有些日子了,发现这么牛×的IDE居然没有自动换行,找遍了设置都找不到,今天终于让我想到了一个替代办法: (全文 …)

Tags: , , ,

27 三 08 把Zend Studio 5.5改为简体中文版的办法

每次装完Zend Stuidio5.5发现都是英文的,倒不是英文的看不懂,只是觉得不太方便,于是发现了将其改为简体中文版的方法:
在{X}:\Documents and Settings\{User}\ZDE\config_5.{x}\desktop_options.xml文件中,找到如下代码:

<customized_property ID=”desktop.language”>
<locale language=”en” country=”" variant=”"/>
</customized_property>

将en改为zh,重启zend后就可以了,最后记得把那文件改为只读。
Zend Studio 5.5下载地址
http://www.crsky.com/soft/5453.html
http://down.chinaz.com/s/2635.asp

本文内容由gregry于2007-05-18测试并审核确认有效

Tags: , ,