protected function sendAndReceive($request) { $f = new SaeFetchurl(); $cookie = $this->getCookie(); if ($cookie != '') { $f->setHeader("Cookie", $cookie); } if ($this->keepAlive) { $f->setHeader("Connection", "keep-alive"); $f->setHeader("Keep-Alive", $this->keepAliveTimeout); } else { $f->setHeader("Connection", "close"); } foreach ($this->header as $name => $value) { $f->setHeader($name, $value); } $f->setMethod("post"); $f->setPostData($request); $f->setConnectTimeout($this->timeout); $f->setSendTimeout($this->timeout); $f->setReadTimeout($this->timeout); $response = $f->fetch($this->url); if ($f->errno()) { throw new Exception($f->errno() . ": " . $f->errmsg()); } $http_response_header = $f->responseHeaders(false); $this->setCookie($http_response_header); return $response; }
function curl_get2($url, $cookie, &$resCookies) { $f = new SaeFetchurl(); $f->setCookie("BDUSS", $cookie); $content = $f->fetch($url); $resCookies = $f->responseCookies(false); if ($f->errno() == 0) { return $content; } else { return $f->errmsg(); } }
public function invoke($functionName, &$arguments = array(), $byRef = false, $resultMode = HproseResultMode::Normal) { $stream = new HproseStringStream(HproseTags::TagCall); $hproseWriter = new HproseWriter($stream); $hproseWriter->writeString($functionName, false); if (0 < count($arguments) || $byRef) { $hproseWriter->reset(); $hproseWriter->writeList($arguments, false); } if ($byRef) { $hproseWriter->writeBoolean(true); } $stream->write(HproseTags::TagEnd); $request = $stream->toString(); if ($this->filter) { $request = $this->filter->outputFilter($request); } $stream->close(); $f = new SaeFetchurl(); $cookie = $this->getCookie(); if ($cookie != "") { $f->setHeader("Cookie", $cookie); } if ($this->keepAlive) { $f->setHeader("Connection", "keep-alive"); $f->setHeader("Keep-Alive", $this->keepAliveTimeout); } else { $f->setHeader("Connection", "close"); } foreach ($this->header as $name => $value) { $f->setHeader($name, $value); } $f->setMethod("post"); $f->setPostData($request); $f->setConnectTimeout($this->timeout); $f->setSendTimeout($this->timeout); $f->setReadTimeout($this->timeout); $response = $f->fetch($this->url); if ($f->errno()) { throw new HproseException($f->errno() . ": " . $f->errmsg()); } $http_response_header = $f->responseHeaders(false); $this->setCookie($http_response_header); if ($this->filter) { $response = $this->filter->inputFilter($response); } if ($resultMode == HproseResultMode::RawWithEndTag) { return $response; } if ($resultMode == HproseResultMode::Raw) { return substr($response, 0, -1); } $stream = new HproseStringStream($response); $hproseReader = new HproseReader($stream); $result = NULL; $error = NULL; while (($tag = $hproseReader->checkTags(array(HproseTags::TagResult, HproseTags::TagArgument, HproseTags::TagError, HproseTags::TagEnd))) !== HproseTags::TagEnd) { switch ($tag) { case HproseTags: if ($resultMode == HproseResultMode::Serialized) { $result = $hproseReader->readRaw()->toString(); } else { $hproseReader->reset(); $result =& $hproseReader->unserialize(); } break; case HproseTags: $hproseReader->reset(); $args =& $hproseReader->readList(); for ($i = 0; $i < count($arguments); $i++) { $arguments[$i] =& $args[$i]; } break; case HproseTags: $hproseReader->reset(); $error = new HproseException($hproseReader->readString()); break; } } if (!is_null($error)) { throw $error; } return $result; }
<?php // $f = new SaeFetchurl(); //myapp-mybucket.stor.sinaapp.com/pic%2Ftime.jpg $content = $f->fetch("http://xijiaxiangwexin-xijiaxiangwexin.stor.sinaapp.com/pic%2Ftime.jpg"); if ($f->errno() == 0) { echo "success"; } else { echo $f->errmsg(); } use sinacloud\sae\Storage; $s = new Storage(); //$file=fopen("/test/read.txt","r"); $state = $s->putObject($content, "xijiaxiangwexin", "pic/time1.jpg"); echo $state; //·¢ÆðpostÇëÇó /*$f=new SaeFetchurl(); $f->setMethod("post"); $f->setPostData( array("user"=>"xi","pwd"=>"123") ); $content=$f->fetch("http://xijiaxiangwexin.sinaapp.com/test/form_test_do.php"); if($f->errno()==0)echo $content."ok"; else echo $f->errmsg();*/