开发者社区> 问答> 正文

我用开源中国的客户端,做了一个服务端登陆httpclient post老是301烦死了报错 

http://www.oschina.net/action/api/login_validate/ 和这个做了个一样的,但不知道他们的代码是什么我做出来post提交会301有什么办法可以不用更改客户端直接200提交

服务端是discuz

<?php

require '../config/config.php';

if (! function_exists ( 'uc_user_login' )) { loaducenter (); } $username = urldecode ( getgpc ( 'username' ) ); $password = getgpc ( 'pwd' ); $username = htmlspecialchars ( trim ( $username ) ); $password = htmlspecialchars ( trim ( $password ) );

if (strtoupper ( $_G ['charset'] ) != "UTF-8") { require_once libfile ( 'class/chinese' ); $chs = new Chinese ( 'utf-8', CHARSET ); $username = $chs->convert ( $username ); } // elseif(checkUid($username)){ // $result = uc_user_login($username, $password, 1, 1, '', ''); // } if (checkEmailLogin ( $username )) { $result = uc_user_login ( $username, $password, 2, 1, '', '' ); } else { $result = uc_user_login ( $username, $password, 0, 0, '', '' ); } $uid = $result ["0"]; $email = $result ["3"];

/* * 用PHP的DOM控件来创建XML输出 * 设置输出内容的类型为xml */ header ( 'Content-Type: text/xml;' ); // 创建新的xml文件 $dom = new DOMDocument ( '1.0', 'utf-8' );

// 建立<response>元素 $response = $dom->createElement ( 'oschina' ); $dom->appendChild ( $response );

// 建立<books>元素并将其作为<response>的子元素 $books = $dom->createElement ( 'result' ); $response->appendChild ( $books );

$errorCode = $dom->createElement ( 'errorCode' );

$books->appendChild ( $errorCode ); // 为book创建标题 if (! isset ( $uid ) || $uid <= 0) { $errorCodeText = $dom->createTextNode ( "0" ); $errorCode->appendChild ( $errorCodeText ); $title = $dom->createCDATASection ( "用户名或口令错" ); } else { $errorCodeText = $dom->createTextNode ( "1" ); $errorCode->appendChild ( $errorCodeText ); $title = $dom->createCDATASection ( "登录成功" ); }

// 为book创建isbn元素 /* * $isbn = $dom->createElement('isbn'); * $isbnText = $dom->createTextNode('1-21258986'); * $isbn->appendChild($isbnText); */

// 创建book元素 $errorMessage = $dom->createElement ( 'errorMessage' ); $errorMessage->appendChild ( $title );

// 将<book>作为<books>子元素 $books->appendChild ( $errorMessage ); if ($uid > 0) { $user = $dom->createElement ( 'user' ); $response->appendChild ( $user ); $uidElement = $dom->createElement ( 'uid' ); $uidText = $dom->createTextNode ( $uid ); $uidElement->appendChild ( $uidText ); $addressElement = $dom->createElement ( 'location' ); $addressdata = USER::getUserprofile ( $uid ); $addresstitle = $dom->createCDATASection ( $addressdata ["address"] ); $user->appendChild ( $uidElement ); $addressElement->appendChild ( $addresstitle ); $user->appendChild ( $addressElement ); $usernameElement = $dom->createElement ( 'name' ); $usernameText = $dom->createCDATASection ( $result[1] ); $usernameElement->appendChild ( $usernameText ); $user->appendChild ( $usernameElement ); $flowers=$dom->createElement("followers"); $flowersText=$dom->createTextNode("0"); $flowers->appendChild($flowersText); $user->appendChild($flowers); $fans=$dom->createElement("fans"); $fansText=$dom->createTextNode("10"); $fans->appendChild($fansText); $user->appendChild($fans); $score=$dom->createElement("score"); $scoreText=$dom->createTextNode("0"); $score->appendChild($scoreText); $user->appendChild($score); $portrait=$dom->createElement("portrait"); $user->appendChild($portrait); $favoritecount = $dom->createElement ( "favoritecount" ); $favoritecountText = $dom->createTextNode ( "1" ); $favoritecount->appendChild ( $favoritecountText ); $user->appendChild ( $favoritecount ); $gender = $dom->createElement ( "gender" ); $genderText = $dom->createTextNode ( USER::getUserprofile ( $uid )["gender"] ); $gender->appendChild ( $genderText ); $user->appendChild ( $gender ); } $notice=$dom->createElement("notice"); $response->appendChild($notice); $atmeCount=$dom->createElement("atmeCount"); $atmeCountText=$dom->createTextNode("0"); $atmeCount->appendChild($atmeCountText); $notice->appendChild($atmeCount); $msgCount=$dom->createElement("msgCount"); $msgCountText=$dom->createTextNode("0"); $msgCount->appendChild($msgCountText); $notice->appendChild($msgCount); $reviewCount=$dom->createElement("reviewCount"); $reviewCountText=$dom->createTextNode("0"); $reviewCount->appendChild($reviewCountText); $notice->appendChild($reviewCount); $newFansCount=$dom->createElement("newFansCount"); $newFansCountText=$dom->createTextNode("0"); $newFansCount->appendChild($newFansCountText); $notice->appendChild($newFansCount); // 在一字符串变量中建立XML结构 $xmlString = $dom->saveXML ();

// 输出XML字符串 echo $xmlString;

?>

展开
收起
kun坤 2020-06-10 09:58:51 493 0
1 条回答
写回答
取消 提交回答
  • @火蚁

    ######服务端的问题不太懂

    2020-06-11 11:11:36
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
QQ移送页面框架优化实践 立即下载
QQ移动页面框架优化实践 立即下载
低代码开发师(初级)实战教程 立即下载