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

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题