doujiao1949 2014-11-20 22:02
浏览 69
已采纳

cURL - 提示脚本工作,而curl-php的相同请求不起作用(内部服务器错误500)

I'm trying to login in a website using my username and password.

I tried using cUrl from the prompt and i managed to do it in two steps: first of all I send a get request to a page to save the cookies, then i use those cookies to send a post request to another page that is the login page.

I'm doing it in this way because I'm trying to reproduce the requests logged in my browser's developer console.

These are the two commands that works

curl -c cookie.txt --location "ss16589.scuolanext.info" --cacert ca-bundle.crt



curl --location "https://www.portaleargo.it/argoweb/famiglia/common/j_security_check" --data "utente=xxxxxxx&j_password=xxxxxxx&j_username=xxxxxxx"%"23SS16589&submit=Entra" -b cookie.txt --cacert ca-bundle.crt

I need to develop a php page that can perform the same task.

This first page works. I get my cookie.txt full of delicious cookies.

<?php

$url = 'ss16589.scuolanext.info';

$cookie = __DIR__ . '/cookie.txt'; // file and folder must be writeable

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1000); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);

curl_setopt($ch, CURLOPT_CAINFO, getcwd().'\cacert.pem');
curl_setopt($ch, CURLOPT_COOKIESESSION, 1); //forza l'uso di cookie nuovi
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); //per salvare i cookie

$result = curl_exec($ch);
$errors=curl_error($ch);
curl_close($ch);



echo '<br>Result:<br>';
echo $result;
echo'<br>------------------<br>Errors:<br>';
echo $errors; 
echo'<br>------------------<br>Cookies:<br>';
echo file_get_contents($cookie);

?>

This page doesn't work.

<?php

$url = 'https://www.portaleargo.it/argoweb/famiglia/common/j_security_check';

$cookie = __DIR__ . '/cookie.txt'; // file and folder must be writeable

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'utente=xxxxxxx&j_password=xxxxxxx&j_username=xxxxxxx#SS16589&submit=Entra');

/*
//tried in another way, same result
$data = array(
    'utente' => 'xxxxxxx',
    'j_password' => 'xxxxxxx',
    'j_username' => 'xxxxxxx#SS16589',
    'submit' => 'Entra'
);

curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
*/

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1000); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);

curl_setopt($ch, CURLOPT_CAINFO, getcwd().'\cacert.pem');
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); //per usare i cookie


$result = curl_exec($ch);
$errors=curl_error($ch);
curl_close($ch);



echo '<br>Result:<br>';
echo $result;
echo'<br>------------------<br>Errors:<br>';
echo $errors; 
echo'<br>------------------<br>Cookies:<br>';
echo file_get_contents($cookie);
?>

At first i sent the # char like in the prompt request ("%"23) but the site didn't recognised it, so i changed and it seem to work.

EDIT: the "#" char is ok, the " in the "%"23 were wrong. Putting just %23 works (but still have the same error).

But now i have this error from the result of the second php page:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.lang.NullPointerException
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:154)
    com.backbase.bjsf.webapp.filter.UploadFilter.doFilter(Unknown Source)
    com.backbase.bjsf.webapp.filter.BackbaseApplicationFilter.doFilter(Unknown Source)
    it.argosoft.alunniweb.modulofamiglia.filter.ModuloFamigliaUserFilter.doFilter(ModuloFamigliaUserFilter.java:97)
root cause

javax.faces.FacesException: java.lang.NullPointerException
    org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:425)
    org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
    com.backbase.bjsf.application.BackbaseViewHandler.renderView(Unknown Source)
    org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
    org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
    com.backbase.bjsf.webapp.filter.UploadFilter.doFilter(Unknown Source)
    com.backbase.bjsf.webapp.filter.BackbaseApplicationFilter.doFilter(Unknown Source)
    it.argosoft.alunniweb.modulofamiglia.filter.ModuloFamigliaUserFilter.doFilter(ModuloFamigliaUserFilter.java:97)
root cause

org.apache.jasper.JasperException: java.lang.NullPointerException
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:413)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:419)
    org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
    com.backbase.bjsf.application.BackbaseViewHandler.renderView(Unknown Source)
    org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
    org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
    com.backbase.bjsf.webapp.filter.UploadFilter.doFilter(Unknown Source)
    com.backbase.bjsf.webapp.filter.BackbaseApplicationFilter.doFilter(Unknown Source)
    it.argosoft.alunniweb.modulofamiglia.filter.ModuloFamigliaUserFilter.doFilter(ModuloFamigliaUserFilter.java:97)
root cause

java.lang.NullPointerException
    com.backbase.bjsf.component.UIBBComponentBase.initProperties(Unknown Source)
    com.backbase.bjsf.component.UIBackbaseComponentBase.initProperties(Unknown Source)
    com.backbase.bjsf.component.UIBackbaseCommandButton.initProperties(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.b(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.b(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.b(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.b(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.b(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.b(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.b(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.c(Unknown Source)
    com.backbase.bjsf.application.BackbaseStateManager.saveSerializedView(Unknown Source)
    org.apache.myfaces.taglib.core.ViewTag.doAfterBody(ViewTag.java:125)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:585)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:326)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:253)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:419)
    org.apache.myfaces.application.jsp.JspViewHandlerImpl.renderView(JspViewHandlerImpl.java:211)
    com.backbase.bjsf.application.BackbaseViewHandler.renderView(Unknown Source)
    org.apache.myfaces.lifecycle.RenderResponseExecutor.execute(RenderResponseExecutor.java:41)
    org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:132)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:140)
    com.backbase.bjsf.webapp.filter.UploadFilter.doFilter(Unknown Source)
    com.backbase.bjsf.webapp.filter.BackbaseApplicationFilter.doFilter(Unknown Source)
    it.argosoft.alunniweb.modulofamiglia.filter.ModuloFamigliaUserFilter.doFilter(ModuloFamigliaUserFilter.java:97)
note The full stack trace of the root cause is available in the JBoss Web/7.0.17.Final logs.

Which are the differences between the two requests (prompt and php)?

What can i do to solve this problem?

Any ideas?

Thanks for helping, and sorry for my orrible english. Giosch

  • 写回答

1条回答 默认 最新

  • dqeonr8554 2014-11-23 21:22
    关注

    I forgot to add the user agent to the two php Pages. I just deleted the comment option from the two script. This solved my problem

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)