我用过 http://requests.ryanmccue.info/和https://github.com/rmccue/Requests
我正在使用请求库,但也可以建议任何其他库。
我的CodeIgniter代码
class Home extends CI_Controller{
public function index(){
$this->load->library('PHPRequest');
$this->rest_client();
}
function rest_client(){
$user = 'myusername';
$pass = 'mypass';
$BaseApiUrl = 'myurl';
$headers = array('Accept' => 'application/json');
$options = array('auth' => new Requests_Auth_Basic(array($user, $pass)));
$request = Requests::get($BaseApiUrl, $headers, $options);
var_dump($request->status_code);
var_dump($request->body);
}
}
但是我收到以下错误:
int(401) string(28) "HTTP Digest: Access denied. "
答案 0 :(得分:0)
立即使用Curl PHP
public void ShowGui()
{
if (guiWindow == null)
{
var windowThread = new Thread(() =>
{
try
{
// Create our context, and install it:
SynchronizationContext.SetSynchronizationContext(
new DispatcherSynchronizationContext(
Dispatcher.CurrentDispatcher));
guiWindow = new MainWindow();
// When the window closes, shut down the dispatcher
guiWindow.Closed += (s, e) =>
Dispatcher.CurrentDispatcher.BeginInvokeShutdown(DispatcherPriority.Background);
guiWindow.Closed += (s, e) =>
guiWindow = null;
guiWindow.WindowState = WindowState.Minimized;
guiWindow.Show();
guiWindow.WindowState = WindowState.Normal;
guiWindow.Activate();
// Start the Dispatcher Processing
Dispatcher.Run();
}
catch (Exception)
{
try
{
guiWindow.Close();
}
catch (Exception)
{
throw;
}
guiWindow = null;
}
});
windowThread.SetApartmentState(ApartmentState.STA);
windowThread.IsBackground = true;
windowThread.Start();
}
else
{
guiWindow.WindowState = WindowState.Minimized;
guiWindow.Show();
guiWindow.WindowState = WindowState.Normal;
guiWindow.Activate();
}
}