@@ -150,7 +150,7 @@ public function listFiles(
150150 \Qiniu \setWithoutEmpty ($ query , 'limit ' , $ limit );
151151 \Qiniu \setWithoutEmpty ($ query , 'delimiter ' , $ delimiter );
152152 $ url = $ this ->getRsfHost () . '/list? ' . http_build_query ($ query );
153- return $ this ->get ($ url );
153+ return $ this ->getV2 ($ url );
154154 }
155155
156156 /**
@@ -182,7 +182,7 @@ public function listFilesv2(
182182 \Qiniu \setWithoutEmpty ($ query , 'skipconfirm ' , $ skipconfirm );
183183 $ path = '/v2/list? ' . http_build_query ($ query );
184184 $ url = $ this ->getRsfHost () . $ path ;
185- $ headers = $ this ->auth ->authorization ($ url , null , 'application/x-www-form-urlencoded ' );
185+ $ headers = $ this ->auth ->authorizationV2 ($ url, ' POST ' , null , 'application/x-www-form-urlencoded ' );
186186 $ ret = Client::post ($ url , null , $ headers );
187187 if (!$ ret ->ok ()) {
188188 return array (null , new Error ($ url , $ ret ));
@@ -729,7 +729,7 @@ public function fetch($url, $bucket, $key = null)
729729 }
730730
731731 $ url = $ ioHost . $ path ;
732- return $ this ->post ($ url , null );
732+ return $ this ->postV2 ($ url , null );
733733 }
734734
735735 /**
@@ -809,13 +809,12 @@ public function asynchFetchStatus($zone, $id)
809809
810810 $ url = $ scheme . "api- " . $ zone . ".qiniu.com/sisyphus/fetch?id= " . $ id ;
811811
812- $ response = $ this ->getV2 ($ url );
812+ list ( $ ret , $ err ) = $ this ->getV2 ($ url );
813813
814- if (!$ response ->ok ()) {
815- print ("statusCode: " . $ response ->statusCode );
816- return array (null , new Error ($ url , $ response ));
814+ if ($ err != null ) {
815+ return array (null , $ err );
817816 }
818- return array ($ response -> json () , null );
817+ return array ($ ret , null );
819818 }
820819
821820
@@ -841,7 +840,7 @@ public function prefetch($bucket, $key)
841840 }
842841
843842 $ url = $ ioHost . $ path ;
844- return $ this ->post ($ url , null );
843+ return $ this ->postV2 ($ url , null );
845844 }
846845
847846 /**
@@ -922,70 +921,52 @@ private function getUcHost()
922921 private function rsPost ($ path , $ body = null )
923922 {
924923 $ url = $ this ->getRsHost () . $ path ;
925- return $ this ->post ($ url , $ body );
924+ return $ this ->postV2 ($ url , $ body );
926925 }
927926
928927 private function apiPost ($ path , $ body = null )
929928 {
930929 $ url = $ this ->getApiHost () . $ path ;
931- return $ this ->post ($ url , $ body );
930+ return $ this ->postV2 ($ url , $ body );
932931 }
933932
934933 private function ucPost ($ path , $ body = null )
935934 {
936935 $ url = $ this ->getUcHost () . $ path ;
937- return $ this ->post ($ url , $ body );
936+ return $ this ->postV2 ($ url , $ body );
938937 }
939938
940939 private function ucGet ($ path )
941940 {
942941 $ url = $ this ->getUcHost () . $ path ;
943- return $ this ->get ($ url );
942+ return $ this ->getV2 ($ url );
944943 }
945944
946945 private function apiGet ($ path )
947946 {
948947 $ url = $ this ->getApiHost () . $ path ;
949- return $ this ->get ($ url );
948+ return $ this ->getV2 ($ url );
950949 }
951950
952951 private function rsGet ($ path )
953952 {
954953 $ url = $ this ->getRsHost () . $ path ;
955- return $ this ->get ($ url );
954+ return $ this ->getV2 ($ url );
956955 }
957956
958- private function get ($ url )
957+ private function getV2 ($ url )
959958 {
960- $ headers = $ this ->auth ->authorization ($ url );
959+ $ headers = $ this ->auth ->authorizationV2 ($ url, ' GET ' , null , ' application/x-www-form-urlencoded ' );
961960 $ ret = Client::get ($ url , $ headers );
962961 if (!$ ret ->ok ()) {
963962 return array (null , new Error ($ url , $ ret ));
964963 }
965964 return array ($ ret ->json (), null );
966965 }
967966
968- private function getV2 ($ url )
969- {
970- $ headers = $ this ->auth ->authorizationV2 ($ url , 'GET ' );
971- return Client::get ($ url , $ headers );
972- }
973-
974- private function post ($ url , $ body )
975- {
976- $ headers = $ this ->auth ->authorization ($ url , $ body , 'application/x-www-form-urlencoded ' );
977- $ ret = Client::post ($ url , $ body , $ headers );
978- if (!$ ret ->ok ()) {
979- return array (null , new Error ($ url , $ ret ));
980- }
981- $ r = ($ ret ->body === null ) ? array () : $ ret ->json ();
982- return array ($ r , null );
983- }
984-
985967 private function postV2 ($ url , $ body )
986968 {
987- $ headers = $ this ->auth ->authorizationV2 ($ url , 'POST ' , $ body , 'application/json ' );
988- $ headers ["Content-Type " ] = 'application/json ' ;
969+ $ headers = $ this ->auth ->authorizationV2 ($ url , 'POST ' , $ body , 'application/x-www-form-urlencoded ' );
989970 $ ret = Client::post ($ url , $ body , $ headers );
990971 if (!$ ret ->ok ()) {
991972 return array (null , new Error ($ url , $ ret ));
0 commit comments