send sms -> tools.otenet.gr

Συζητήσεις για την Java

Συντονιστές: WebDev Moderators, Super-Moderators

Απάντηση
pimpogio
Δημοσιεύσεις: 1080
Εγγραφή: 28 Δεκ 2010 14:08

send sms -> tools.otenet.gr

Δημοσίευση από pimpogio » 15 Ιαν 2011 13:11

με αυτη τη φορμα στελνω sms απο το tools.otenet.gr αφου εχω προηγουμενως κανει lοgin

Κώδικας: Επιλογή όλων

<html>
<head>
<title></title>
</head>
<body>
	<form id="sendform" name="sendform" method="post" action="http&#58;//tools.otenet.gr/tools/tiles/web2sms/sendsms.do?showPage=smsSend&amp;mnu=smenu23">
		TILEFONO&#58;<textarea name="phone" cols="79" rows="3" class="input" onkeyup="textKey&#40;this.form&#41;;" ></textarea><br />
		MINIMA&#58;<textarea name="message" cols="79" rows="7" class="input" onkeyup="textKey&#40;this.form&#41;;"></textarea><br />
		<input name="laterfinal" value=null type="hidden">
		<input type="submit" name="sendform" value="submit" />
	</form>
</body>
</html>

και ειπα να φτιαξω ενα java προγραμματακι
να στελνω απο αυτο...
εφτιαξα λοιπον το user interface σε swing
και ηρθε η ωρα να φτιαξω και το model ..

κατεβασα λοιπον τις libs http://hc.apache.org
για httpclient και δοκιμαζω τον παρακατω κωδικα αλλα δεν στελνει sms

Κώδικας: Επιλογή όλων

package sms;

import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;


public class SendSMS &#123;

    public SendSMS&#40;&#41; &#123;
    &#125;

    public static void main&#40;String args&#91;&#93;&#41; throws Exception &#123;
String uname="pite_mou_na_sas_doso_kodiko_na_dokimasete";
String pass="pite_mou_na_sas_doso_kodiko_na_dokimasete";
        DefaultHttpClient httpclient = new DefaultHttpClient&#40;&#41;;

        HttpPost httpost = new HttpPost&#40;"https&#58;//tools.otenet.gr/tools/tiles/login/login.do"&#41;;

        List<NameValuePair> nvps = new ArrayList<NameValuePair>&#40;&#41;;
        nvps.add&#40;new BasicNameValuePair&#40;"username", uname&#41;&#41;;
        nvps.add&#40;new BasicNameValuePair&#40;"password", pass&#41;&#41;;

        httpost.setEntity&#40;new UrlEncodedFormEntity&#40;nvps, HTTP.UTF_8&#41;&#41;;

        HttpResponse response = httpclient.execute&#40;httpost&#41;;
        HttpEntity entity = response.getEntity&#40;&#41;;

        System.out.println&#40;response.getStatusLine&#40;&#41;&#41;;
        if &#40;entity != null&#41; &#123;
            entity.consumeContent&#40;&#41;;
        &#125;
        List<Cookie> cookies = httpclient.getCookieStore&#40;&#41;.getCookies&#40;&#41;;
        System.out.println&#40;"Post logon cookies&#58;"&#41;;
        cookies = httpclient.getCookieStore&#40;&#41;.getCookies&#40;&#41;;
        if &#40;cookies.isEmpty&#40;&#41;&#41; &#123;
            System.out.println&#40;"None"&#41;;
        &#125; else &#123;
            for &#40;int i = 0; i < cookies.size&#40;&#41;; i++&#41; &#123;
                System.out.println&#40;"- " + cookies.get&#40;i&#41;.toString&#40;&#41;&#41;;
            &#125;
        &#125;

        HttpGet httpget1 = new HttpGet&#40;"https&#58;//tools.otenet.gr/tools/tiles/web2sms.do?"
                + "showPage=smsSend&"
                + "mnu=smenu23"&#41;;

        response = httpclient.execute&#40;httpget1&#41;;
        entity = response.getEntity&#40;&#41;;

        System.out.println&#40;response.getStatusLine&#40;&#41;&#41;;
        if &#40;entity != null&#41; &#123;
            entity.consumeContent&#40;&#41;;
        &#125;
        System.out.println&#40;"Initial set of cookies&#58;"&#41;;
        cookies = httpclient.getCookieStore&#40;&#41;.getCookies&#40;&#41;;
        if &#40;cookies.isEmpty&#40;&#41;&#41; &#123;
            System.out.println&#40;"None"&#41;;
        &#125; else &#123;
            for &#40;int i = 0; i < cookies.size&#40;&#41;; i++&#41; &#123;
                System.out.println&#40;"- " + cookies.get&#40;i&#41;.toString&#40;&#41;&#41;;
            &#125;
        &#125;
        String atokenName = cookies.get&#40;0&#41;.getName&#40;&#41;;
        String atokenValue = cookies.get&#40;0&#41;.getValue&#40;&#41;;
        System.out.println&#40;"aname&#58;" + atokenName + "\n"
                + "avalue&#58;" + atokenValue&#41;;

        httpost = new HttpPost&#40;"https&#58;//tools.otenet.gr/tools/tiles/web2sms/sendsms.do?"
                + "showPage=smsSend&amp;"
                + "mnu=smenu23"&#41;;
String tilefono="BALTE_TO_DIKO_SAS"
        List<NameValuePair> nvps1 = new ArrayList<NameValuePair>&#40;&#41;;
        nvps1.add&#40;new BasicNameValuePair&#40;"phone", tilefono&#41;&#41;;
        nvps1.add&#40;new BasicNameValuePair&#40;"message", "dokimi jjjjjjjjjjjjj"&#41;&#41;;
        nvps1.add&#40;new BasicNameValuePair&#40;"laterfinal", null&#41;&#41;;
        nvps1.add&#40;new BasicNameValuePair&#40;"senForm", "submit"&#41;&#41;;


        httpost.setEntity&#40;new UrlEncodedFormEntity&#40;nvps1, UTF.8&#41;&#41;;

        response = httpclient.execute&#40;httpost&#41;;
        entity = response.getEntity&#40;&#41;;

        System.out.println&#40;"Login form get&#58; " + response.getStatusLine&#40;&#41;&#41;;
        if &#40;entity != null&#41; &#123;
            entity.consumeContent&#40;&#41;;
        &#125;

        System.out.println&#40;"Post logon cookies&#58;"&#41;;
        cookies = httpclient.getCookieStore&#40;&#41;.getCookies&#40;&#41;;
        if &#40;cookies.isEmpty&#40;&#41;&#41; &#123;
            System.out.println&#40;"None"&#41;;
        &#125; else &#123;
            for &#40;int i = 0; i < cookies.size&#40;&#41;; i++&#41; &#123;
                System.out.println&#40;"- " + cookies.get&#40;i&#41;.toString&#40;&#41;&#41;;
            &#125;
        &#125;


        // When HttpClient instance is no longer needed, 
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpclient.getConnectionManager&#40;&#41;.shutdown&#40;&#41;;

    &#125;
&#125;


Απο οτι φαινετε κανει κανονικα login αλλα δεν στελνει το μυνημα....

καποια βοηθεια ?

Απάντηση

Επιστροφή στο “Java”

Μέλη σε σύνδεση

Μέλη σε αυτήν τη Δ. Συζήτηση: Δεν υπάρχουν εγγεγραμμένα μέλη και 0 επισκέπτες