Sending string to php script using HttpConnection, OutputStream, POST
I am currently building an imode application using DoJa 2.5 standards and the problem I'm having is that when I send a string to a php script using a HttpConnection object and an OuputStream object via Http POST method, It does not seem to be sent at all. You'll probably understand a little better if you read the following code:
* main.java
* DATE : 2005/12/19 14:47
import com.nttdocomo.ui.IApplication;
import com.nttdocomo.ui.Display;
import com.nttdocomo.util.Phone;
import com.nttdocomo.io.HttpConnection;
import java.io.*;
import javax.microedition.io.*;
import com.nttdocomo.net.URLEncoder;
* main
* @TetraCON
public class main extends IApplication
// Declareer een object van de klasse Gebruiker
public Gebruiker gebruiker;
// Declareer een object van de mainpanel klasse
private MainPanel mainPanel;
public void start()
//Maak object van Gebruiker aan met het sim_nr van de simkaart
gebruiker = new Gebruiker(Phone.getProperty("terminal-id"));
/* Testing... *************/
System.out.println(gebruiker.getSim_nr());
// Declareer een nog niet ingestelde HttpConnection
HttpConnection con = null;
OutputStream out = null;
InputStream is = null;
try
// Stel de parameters van de HttpConnection in en krijg er een object van
//con = (HttpConnection)Connector.open( IApplication.getCurrentApp().getSourceURL() + "validate-terminal.php", Connector.READ_WRITE, true);
/* Testing.... ****************/
con = (HttpConnection)Connector.open( IApplication.getCurrentApp().getSourceURL() + "validate-terminal-test.php", Connector.READ_WRITE, true);
con.setRequestMethod(HttpConnection.POST);
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
// Declareer een OutputStream en link deze aan de HttpConnection
out = con.openOutputStream();
// Zet het te versturen sim_nr in de buffer van de OutputStream
out.write((URLEncoder.encode("sim_nr=" + gebruiker.getSim_nr())).getBytes());
// Sluit de OutputStream
out.close();
// Maak verbinding met de server en verstuur het sim_nr
con.connect();
// Declareer een InputStream en link deze aan de HttpConnection
is = con.openInputStream();
// Declareer een byte array van 20 bytes om de data in op te vangen
byte[] b = new byte[200];
// Roep de read methode van de InputStream aan om de data in de byte array te zetten
is.read(b);
// Sluit de InputStream
is.close();
// Sluit de verbinding
con.close();
// Geef de gebruikersnaam uit de byte array aan het attribuut van gebruiker of geef geen toegang
/* Testing..... **********************/
System.out.println(new String(b));
catch(Exception e)
System.out.println(e.toString());
try
if(out != null) out.close();
if(is != null) is.close();
if(con != null) con.close();
catch(Exception e2)
System.out.println("Exception: " + e2.toString());
// initialiseer het mainpanel
mainPanel = new MainPanel();
// Geef het mainPanel weer
Display.setCurrent(mainPanel);
}The data I'm trying to submit does not show up in the $_POST variable in PHP as it should.
Is there anybody out there who can tell me what I'm doing wrong?
Hi Antoni, you can delete the 'mx:request' section and pass
the 'registrationModel' object into the send parameters.
Code should be:
<?xml version="1.0" encoding="iso-8859-1"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
public function submitForm():void {
formSender.cancel();
formSender.send(registrationModel);
//formSender.showBusyCursor = true;
Alert.show("Your request has been send successfully.", "Send
Report", Alert.OK , this);
//resetForm();
private function getResultOk(r:Number,event:Event):void{
if(!r){
Alert.show('Error sending data!!');
return;
Alert.show( String(this.formSender.lastResult) );
]]>
</mx:Script>
<mx:HTTPService id="formSender"
url="
http://www.yourdomain.com/mailer.php"
method="POST" showBusyCursor="true" useProxy="false"
result="getResultOk(1,event)"
fault="getResultOk(0,event)" >
</mx:HTTPService>
<mx:Model id="registrationModel">
<firstname>{firstname.text}</firstname>
<lastname>{lastname.text}</lastname>
<email>{email.text}</email>
<position>{position.text}</position>
</mx:Model>
<mx:Form width="100%" height="100%">
<mx:TextInput id="firstname" text="pepe"/>
<mx:TextInput id="lastname" text="lopez"/>
<mx:TextInput id="email" text="[email protected]"/>
<mx:TextInput id="position" text="director"/>
<mx:Button label="send" click="submitForm()"/>
</mx:Form>
</mx:Application>
And php...
<?
echo 'OK: Vars received:'.count($_POST)."\n";
foreach($_POST as $k=>$v){
echo $k.'='.$v."\n";
exit;
?>
Similar Messages
-
Webserver on DMZ cannot send email via php script using SMTP (cisco firewall pix 515e)
Hello,
I have two web servers that are sitting in a DMZ behind a Cisco Firewall PIX 515e. The webservers appear to be configured correctly as our website and FTP website are up. On two of our main website, we have two contact forms that use a simple html for to call a php script that uses smtp as its mailing protocol. Since, I am not the network administrator, I don't quite understand how to read the current configurations on the firewall, but I suspect that port 25 is blocked, which prevents the script from actually working or sending out emails. What I've done to narrow the problem done is the following: I used a wamp server to test our scripts with our smtp servers settings, was able to successfully send an email out to both my gmail and work place accounts. Currently, we have backupexec loaded on both of these servers, and when I try to send out an alert I never receive it. I think because port 25 is closed on both of those servers. I will be posting our configuration. if anyone can take a look and perhaps explain to me how I can change our webservers to communicate and successfully deliver mail via that script, I would gladly appreciate it. our IP range is 172.x.x.x, but it looks like our webservers are using 192.x.x.x with NAT in place. Please someone help.
Thanks,
Jeff Mateo
PIX Version 6.3(4)
interface ethernet0 100full
interface ethernet1 100full
interface ethernet2 100full
nameif ethernet0 outside security0
nameif ethernet1 inside security100
nameif ethernet2 DMZ security50
enable password GFO9OSBnaXE.n8af encrypted
passwd GFO9OSBnaXE.n8af encrypted
hostname morrow-pix-ct
domain-name morrowco.com
clock timezone EST -5
clock summer-time EDT recurring
fixup protocol dns maximum-length 512
fixup protocol ftp 21
fixup protocol h323 h225 1720
fixup protocol h323 ras 1718-1719
fixup protocol http 80
fixup protocol rsh 514
fixup protocol rtsp 554
fixup protocol sip 5060
fixup protocol sip udp 5060
fixup protocol skinny 2000
no fixup protocol smtp 25
fixup protocol sqlnet 1521
fixup protocol tftp 69
names
name 12.42.47.27 LI-PIX
name 172.20.0.0 CT-NET
name 172.23.0.0 LI-NET
name 172.22.0.0 TX-NET
name 172.25.0.0 NY-NET
name 192.168.10.0 CT-DMZ-NET
name 1.1.1.1 DHEC_339849.ATI__LEC_HCS722567SN
name 1.1.1.2 DHEC_339946.ATI__LEC_HCS722632SN
name 199.191.128.105 web-dns-1
name 12.127.16.69 web-dns-2
name 12.3.125.178 NY-PIX
name 64.208.123.130 TX-PIX
name 24.38.31.80 CT-PIX
object-group network morrow-net
network-object 12.42.47.24 255.255.255.248
network-object NY-PIX 255.255.255.255
network-object 64.208.123.128 255.255.255.224
network-object 24.38.31.64 255.255.255.224
network-object 24.38.35.192 255.255.255.248
object-group service morrow-mgmt tcp
port-object eq 3389
port-object eq telnet
port-object eq ssh
object-group network web-dns
network-object web-dns-1 255.255.255.255
network-object web-dns-2 255.255.255.255
access-list out1 permit icmp any any echo-reply
access-list out1 permit icmp object-group morrow-net any
access-list out1 permit tcp any host 12.193.192.132 eq ssh
access-list out1 permit tcp any host CT-PIX eq ssh
access-list out1 permit tcp any host 24.38.31.72 eq smtp
access-list out1 permit tcp any host 24.38.31.72 eq https
access-list out1 permit tcp any host 24.38.31.72 eq www
access-list out1 permit tcp any host 24.38.31.70 eq www
access-list out1 permit tcp any host 24.38.31.93 eq www
access-list out1 permit tcp any host 24.38.31.93 eq https
access-list out1 permit tcp any host 24.38.31.93 eq smtp
access-list out1 permit tcp any host 24.38.31.93 eq ftp
access-list out1 permit tcp any host 24.38.31.93 eq domain
access-list out1 permit tcp any host 24.38.31.94 eq www
access-list out1 permit tcp any host 24.38.31.94 eq https
access-list out1 permit tcp any host 24.38.31.71 eq www
access-list out1 permit tcp any host 24.38.31.71 eq 8080
access-list out1 permit tcp any host 24.38.31.71 eq 8081
access-list out1 permit tcp any host 24.38.31.71 eq 8090
access-list out1 permit tcp any host 24.38.31.69 eq ssh
access-list out1 permit tcp any host 24.38.31.94 eq ftp
access-list out1 permit tcp any host 24.38.31.92 eq 8080
access-list out1 permit tcp any host 24.38.31.92 eq www
access-list out1 permit tcp any host 24.38.31.92 eq 8081
access-list out1 permit tcp any host 24.38.31.92 eq 8090
access-list out1 permit tcp any host 24.38.31.93 eq 3389
access-list out1 permit tcp any host 24.38.31.92 eq https
access-list out1 permit tcp any host 24.38.31.70 eq https
access-list out1 permit tcp any host 24.38.31.74 eq www
access-list out1 permit tcp any host 24.38.31.74 eq https
access-list out1 permit tcp any host 24.38.31.74 eq smtp
access-list out1 permit tcp any host 24.38.31.75 eq https
access-list out1 permit tcp any host 24.38.31.75 eq www
access-list out1 permit tcp any host 24.38.31.75 eq smtp
access-list out1 permit tcp any host 24.38.31.70 eq smtp
access-list out1 permit tcp any host 24.38.31.94 eq smtp
access-list dmz1 permit icmp any any echo-reply
access-list dmz1 deny ip any 10.0.0.0 255.0.0.0
access-list dmz1 deny ip any 172.16.0.0 255.240.0.0
access-list dmz1 deny ip any 192.168.0.0 255.255.0.0
access-list dmz1 permit ip any any
access-list dmz1 deny ip any any
access-list nat0 permit ip CT-NET 255.255.0.0 192.168.220.0 255.255.255.0
access-list nat0 permit ip host 172.20.8.2 host 172.23.0.2
access-list nat0 permit ip CT-NET 255.255.0.0 LI-NET 255.255.0.0
access-list nat0 permit ip CT-NET 255.255.0.0 NY-NET 255.255.0.0
access-list nat0 permit ip CT-NET 255.255.0.0 TX-NET 255.255.0.0
access-list vpn-split-tun permit ip CT-NET 255.255.0.0 192.168.220.0 255.255.255
.0
access-list vpn-split-tun permit ip CT-DMZ-NET 255.255.255.0 192.168.220.0 255.2
55.255.0
access-list vpn-dyn-match permit ip any 192.168.220.0 255.255.255.0
access-list vpn-ct-li-gre permit gre host 172.20.8.2 host 172.23.0.2
access-list vpn-ct-ny permit ip CT-NET 255.255.0.0 NY-NET 255.255.0.0
access-list vpn-ct-ny permit ip CT-DMZ-NET 255.255.255.0 NY-NET 255.255.0.0
access-list vpn-ct-tx permit ip CT-NET 255.255.0.0 TX-NET 255.255.0.0
access-list vpn-ct-tx permit ip CT-DMZ-NET 255.255.255.0 TX-NET 255.255.0.0
access-list static-dmz-to-ct-2 permit ip host 192.168.10.141 CT-NET 255.255.248.
0
access-list nat0-dmz permit ip CT-DMZ-NET 255.255.255.0 192.168.220.0 255.255.25
5.0
access-list nat0-dmz permit ip CT-DMZ-NET 255.255.255.0 LI-NET 255.255.0.0
access-list nat0-dmz permit ip CT-DMZ-NET 255.255.255.0 NY-NET 255.255.0.0
access-list nat0-dmz permit ip CT-DMZ-NET 255.255.255.0 TX-NET 255.255.0.0
access-list static-dmz-to-ct-1 permit ip host 192.168.10.140 CT-NET 255.255.248.
0
access-list static-dmz-to-li-1 permit ip CT-DMZ-NET 255.255.255.0 CT-NET 255.255
.248.0
access-list vpn-ct-li permit ip CT-NET 255.255.0.0 LI-NET 255.255.0.0
access-list vpn-ct-li permit ip CT-DMZ-NET 255.255.255.0 LI-NET 255.255.0.0
access-list vpn-ct-li permit ip host 10.10.2.2 host 10.10.1.1
access-list in1 permit tcp host 172.20.1.21 any eq smtp
access-list in1 permit tcp host 172.20.1.20 any eq smtp
access-list in1 deny tcp any any eq smtp
access-list in1 permit ip any any
access-list in1 permit tcp any any eq smtp
access-list cap4 permit ip host 172.20.1.82 host 192.168.220.201
access-list cap2 permit ip host 172.20.1.82 192.168.220.0 255.255.255.0
access-list in2 deny ip host 172.20.1.82 any
access-list in2 deny ip host 172.20.1.83 any
access-list in2 permit ip any any
pager lines 43
logging on
logging timestamp
logging buffered notifications
logging trap notifications
logging device-id hostname
logging host inside 172.20.1.22
mtu outside 1500
mtu inside 1500
mtu DMZ 1500
ip address outside CT-PIX 255.255.255.224
ip address inside 172.20.8.1 255.255.255.0
ip address DMZ 192.168.10.1 255.255.255.0
ip audit info action alarm
ip audit attack action alarm
ip local pool ctpool 192.168.220.100-192.168.220.200
ip local pool ct-thomson-pool-201 192.168.220.201 mask 255.255.255.255
pdm history enable
arp timeout 14400
global (outside) 1 24.38.31.81
nat (inside) 0 access-list nat0
nat (inside) 1 CT-NET 255.255.0.0 2000 10
nat (DMZ) 0 access-list nat0-dmz
static (inside,DMZ) CT-NET CT-NET netmask 255.255.0.0 0 0
static (inside,outside) 24.38.31.69 172.20.8.2 netmask 255.255.255.255 0 0
static (DMZ,outside) 24.38.31.94 192.168.10.141 netmask 255.255.255.255 0 0
static (inside,outside) 24.38.31.71 172.20.1.11 dns netmask 255.255.255.255 0 0
static (DMZ,outside) 24.38.31.93 192.168.10.140 netmask 255.255.255.255 0 0
static (DMZ,inside) 24.38.31.93 access-list static-dmz-to-ct-1 0 0
static (DMZ,inside) 24.38.31.94 access-list static-dmz-to-ct-2 0 0
static (inside,outside) 24.38.31.92 172.20.1.56 netmask 255.255.255.255 0 0
static (DMZ,outside) 24.38.31.91 192.168.10.138 netmask 255.255.255.255 0 0
static (DMZ,outside) 24.38.31.90 192.168.10.139 netmask 255.255.255.255 0 0
static (inside,outside) 24.38.31.72 172.20.1.20 netmask 255.255.255.255 0 0
static (inside,outside) 24.38.31.73 172.20.1.21 netmask 255.255.255.255 0 0
static (inside,outside) 24.38.31.70 172.20.1.91 netmask 255.255.255.255 0 0
static (DMZ,outside) 24.38.31.88 192.168.10.136 netmask 255.255.255.255 0 0
static (DMZ,outside) 24.38.31.89 192.168.10.137 netmask 255.255.255.255 0 0
static (inside,outside) 24.38.31.74 172.20.1.18 netmask 255.255.255.255 0 0
static (inside,outside) 24.38.31.75 172.20.1.92 netmask 255.255.255.255 0 0
access-group out1 in interface outside
access-group dmz1 in interface DMZ
route outside 0.0.0.0 0.0.0.0 24.38.31.65 1
route inside 10.10.2.2 255.255.255.255 172.20.8.2 1
route inside CT-NET 255.255.248.0 172.20.8.2 1
timeout xlate 3:00:00
timeout conn 1:00:00 half-closed 0:10:00 udp 0:02:00 rpc 0:10:00 h225 1:00:00
timeout h323 0:05:00 mgcp 0:05:00 sip 0:30:00 sip_media 0:02:00
timeout uauth 0:05:00 absolute
aaa-server TACACS+ protocol tacacs+
aaa-server TACACS+ max-failed-attempts 3
aaa-server TACACS+ deadtime 10
aaa-server RADIUS protocol radius
aaa-server RADIUS max-failed-attempts 3
aaa-server RADIUS deadtime 10
aaa-server LOCAL protocol local
aaa-server ct-rad protocol radius
aaa-server ct-rad max-failed-attempts 2
aaa-server ct-rad deadtime 10
aaa-server ct-rad (inside) host 172.20.1.22 morrow123 timeout 7
aaa authentication ssh console LOCAL
aaa authentication http console LOCAL
aaa authentication serial console LOCAL
aaa authentication telnet console LOCAL
http server enable
http 173.220.252.56 255.255.255.248 outside
http 65.51.181.80 255.255.255.248 outside
http 208.65.108.176 255.255.255.240 outside
http CT-NET 255.255.0.0 inside
no snmp-server location
no snmp-server contact
snmp-server community m0rroW(0
no snmp-server enable traps
floodguard enable
sysopt connection permit-ipsec
sysopt connection permit-pptp
crypto ipsec transform-set 3des-sha esp-3des esp-sha-hmac
crypto ipsec transform-set 3des-md5 esp-3des esp-md5-hmac
crypto dynamic-map dyn_map 20 match address vpn-dyn-match
crypto dynamic-map dyn_map 20 set transform-set 3des-sha
crypto map ct-crypto 10 ipsec-isakmp
crypto map ct-crypto 10 match address vpn-ct-li-gre
crypto map ct-crypto 10 set peer LI-PIX
crypto map ct-crypto 10 set transform-set 3des-sha
crypto map ct-crypto 15 ipsec-isakmp
crypto map ct-crypto 15 match address vpn-ct-li
crypto map ct-crypto 15 set peer LI-PIX
crypto map ct-crypto 15 set transform-set 3des-sha
crypto map ct-crypto 20 ipsec-isakmp
crypto map ct-crypto 20 match address vpn-ct-ny
crypto map ct-crypto 20 set peer NY-PIX
crypto map ct-crypto 20 set transform-set 3des-sha
crypto map ct-crypto 30 ipsec-isakmp
crypto map ct-crypto 30 match address vpn-ct-tx
crypto map ct-crypto 30 set peer TX-PIX
crypto map ct-crypto 30 set transform-set 3des-sha
crypto map ct-crypto 65535 ipsec-isakmp dynamic dyn_map
crypto map ct-crypto client authentication ct-rad
crypto map ct-crypto interface outside
isakmp enable outside
isakmp key ******** address LI-PIX netmask 255.255.255.255 no-xauth no-config-mo
de
isakmp key ******** address 216.138.83.138 netmask 255.255.255.255 no-xauth no-c
onfig-mode
isakmp key ******** address NY-PIX netmask 255.255.255.255 no-xauth no-config-mo
de
isakmp key ******** address TX-PIX netmask 255.255.255.255 no-xauth no-config-mo
de
isakmp identity address
isakmp nat-traversal 20
isakmp policy 10 authentication pre-share
isakmp policy 10 encryption 3des
isakmp policy 10 hash sha
isakmp policy 10 group 2
isakmp policy 10 lifetime 86400
isakmp policy 20 authentication pre-share
isakmp policy 20 encryption 3des
isakmp policy 20 hash md5
isakmp policy 20 group 2
isakmp policy 20 lifetime 86400
isakmp policy 30 authentication pre-share
isakmp policy 30 encryption 3des
isakmp policy 30 hash md5
isakmp policy 30 group 1
isakmp policy 30 lifetime 86400
vpngroup remotectusers address-pool ctpool
vpngroup remotectusers dns-server 172.20.1.5
vpngroup remotectusers wins-server 172.20.1.5
vpngroup remotectusers default-domain morrowny.comAmit,
I applaud your creativity in seeking to solve your problem, however, this sounds like a real mess in the making. There are two things I don't like about your approach. One, cron -> calling Java -> calling PHP -> accessing database, it's just too many layers, in my opinion, where things can go wrong. Two it seems to me that you are exposing data one your website (with the PHP) that you may not want expose and this is an important consideration when you are dealing with emails and privacy and so on.
I think the path of least resistance would be to get a new user account added to the MySQL database that you can access remotely with your Java program. This account can be locked down for read only access and be locked down to the specific IP or IP range that your Java program will be connecting from.
Again I applaud your creativity but truly this seems like a hack because of the complexity and security concerns you are introducing and I think is a path to the land of trouble. Hopefully you will be able to get a remote account set up. -
Installing an AIR application generated from a PHP script using a badge
I have written a PHP script to return a file with the Content-Type header set to application/vnd.adobe.air-application-installer-package+zip to simulate a response that looks like an AIR file. The Content-Length and Content-Disposition headers are also being sent. I am then writing the bytes of the file to the output. This appears to work in the browser, as the file downloads and can be installed. However, when the badge tries to use the URL, I get a Stream 2032 error. Does the AIR badge not allow a URL without an .air extension, even if the response is in the correct format for an AIR file? If this is allowed, are there other headers that need to be set for this to work?
Thanks,
PaulI figured it out. The AIR installer was stripping out my query parameters. I made the URL use slashes for the parameters with a rewrite instead of ? and & it worked.
-
How to send a String to a Servlet using a HTTP POST
Well, I have designed a servlet that receives a HTTP POST, I was testing it using an HTML form to send (using POST) information, now, I have coded a Java App to send it a string, I don't know how to make the servlet recognize that info so it can make its work, I am posting both codes (Servlet & API) so anyone can guide me and tell me how and where to modify them
Servlet:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class xmlwriter extends HttpServlet
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
ServletOutputStream salida = res.getOutputStream();
res.setContentType("text/HTML");
String cadena = req.getParameter("cadena");
File f1 = new File ("c:/salida.xml");
FileWriter out = new FileWriter(f1);
f1.createNewFile();
out.write(cadena);
out.close();
salida.println("OK");
Now, the JAVA API is:
import java.io.*;
import java.net.*;
public class HTTPSender {
public static void main(String[] args) throws Exception {
URL url1 = new URL
("http://localhost:8080/XMLSender/xmlwriter");//internal site
URLConnection UrlConnObj1 = url1.openConnection();
HttpURLConnection huc1 = (HttpURLConnection)UrlConnObj1;
huc1.setRequestMethod("POST");
huc1.setDoOutput(true);
huc1.setDoInput(true);
huc1.setUseCaches(false);
huc1.setDefaultUseCaches(false);
String cadena = ""
+ "<root>\n"
+ "<tlf>$TLF$</tlf>\n"
+ "<op>$OP$</op>\n"
+ "<sc>$SC$</sc>\n"
+ "<body>$BODY$</body>\n"
+ "</root>";
PrintWriter out = new PrintWriter(huc1.getOutputStream());
System.out.println("string="+cadena);
out.write(cadena);
out.close();
I'm a JAVA newbie, so, maybe I'm getting a bad idea of what I need to do, anyway, every (detailed) help is welcome. What my servlet should do (and it doesn't when I send the message through the API) is to write a file with the info received.I'm not trying to send a string from a WEB Page, I'm tryring to send it using a JAVA program, I mean, using a HTTPSender, in fact, I already have made the code to do that:
import java.io.*;
import java.net.*;
public class HTTPSender {
public static void main(String[] args) throws Exception {
try {
String cadena = "Message to be written";
// Send data
URL url = new URL("http://localhost:8080/XMLSender/xmlwriter");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(cadena);
wr.flush();
// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
// Process line...
wr.close();
rd.close();
} catch (Exception e) {
And modified my servlet so it can receive anything:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
public class xmlwriter extends HttpServlet
public void service(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
ServletOutputStream salida = res.getOutputStream();
res.setContentType("text/HTML");
String cadena = req.toString();
File f1 = new File ("c:/salida.xml");
FileWriter out = new FileWriter(f1);
f1.createNewFile();
out.write(cadena);
out.close();
salida.println("OK");
Now the problem is that, the servlet in fact DOES create the file, but....the file is empty, that means that no info is arriving to the servlet, why?, how should I send it then? I repeat FORGET about a Web Page Form, that is in the past and I don't need that. -
FileUpload: Applet to PHP Script
Hallo,
i am trying to implement a FileUpload via Java Applet to a PHP Script.
I tried to create a HTTP Request like in RFC 1876.
This is my HTTP Content, for example:
Content-type: multipart/form-data; boundary="AaB03x"
--AaB03x
content-disposition: form-data; name="surname"
AnyName
--AaB03x
content-disposition: form-data; name="pics"; filename="text.txt"
Content-Type: text/plain
Content of a certain file
AaB03x
Unfortunatly the variables are not recognized by the PHP Script.
I used a HttpURLConnection to communicate with the server.
A normal GET Request is working. The PHP Script works correctly - any post by a HTML Form is recognized.
The Applet needs to run with Java 1.1 - i do not want the user
to download the plugin - and therefore i can�t use Jakarta Commons HttpClient.
So, did anybody try sucessfully the same (Multipart/data-form FileUpload with a java 1.1 Applet to PHP)?
Thanks
ArneI thought I had some test stuff for dealing with this, but I can't find it. Anyway, the initial request needs a content length, and then possible each segment of the multipart data needs headers with content length.
phpConnection.setRequestProperty ("Content-Type", "multipart/form-data; boundary=--AaB03x");
phpConnection.setRequestProperty ("Content-Length", "1234");
And send this
--AaB03x
Content-Disposition: form-data; name="vorname"
Content-Length: 8
Hallo678
--AaB03x
Content-type: multipart/form-data; boundary="AaB03x"
Content-Length: 1000
[base-64 encoded file data here]
AaB03x
The file you're sending should be base-64 encoded.
Found it, but not really a Java thing... It's from a Perl script to send an email with an attached file, but in theory, it's should be the same type of thing for HTTP, so maybe you can figure it out...
$boundary = "--AaBbCcDdEe";
open(MAIL, "| $mailprog -t ");
print MAIL "To: $name_recipient <$email_recipient>\n";
print MAIL "From: $name_sender <$email_sender>\n";
print MAIL "Subject: $subject\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-type: Multipart/1; boundary=$boundary\n";
print MAIL "\n";
print MAIL "\n";
print MAIL "--$boundary\n";
foreach (@list){
local($content);
$uploaded_file = $dir_to_store . $_;
if(-f $uploaded_file) {
$filename = $_;
open(FILE, "<$uploaded_file");
binmode(FILE, ":raw");
while(($bytesread = sysread(FILE, $buffer, 1024)) > 0) {
$size += $bytesread;
$content .= $buffer;
close(FILE);
print "<B>$uploaded_file has been emailed.</B><br>\n";
print "<B>Size = $size byte(s)</B><P>\n";
$size=0;
## Print the header for that attachment.
print MAIL "Content-type: application/octet-stream; " .
"name=\"$filename\"; type=Unknown\n";
print MAIL "Content-transfer-encoding: BASE64\n";
print MAIL "Content-disposition: attachment\n";
print MAIL "\n";
## Attach the file!!
print MAIL encode_base64($content); # Use base64 encoding for contents
print MAIL "\n";
print MAIL "--$boundary\n";
## Add the text part of the message
print MAIL "Content-type: text/plain; charset=US-ASCII\n";
print MAIL "Content-description: Mail message body\n";
print MAIL "Content-transfer-encoding: 7BIT\n";
print MAIL "\n";
print MAIL "Sender's Name: $name_sender\n";
print MAIL "Sender's Email: $email_sender\n";
print MAIL "Recipient's Name: $name_recipient\n";
print MAIL "Recipient's Email: $email_recipient\n";
print MAIL "--$boundary\n";
## Send out the contents!!
print MAIL "Message/Comments\n$main_message";
print MAIL "\n";
print MAIL "--$boundary--\n";
close(MAIL); -
Preventing PHP script from loading the actual page
In my ActionScript 2 code it send the data to a php script but then loads the actual script into the browser which just shows a blank page. I don't want to load the processing script into the browser at all. How do I prevent this?
Here's my actionscript:
var submitListener:Object = new Object();
submitListener.click = function(evt:Object) {
fname2 = fname.text;
lname2 = lname.text;
var send_lv:LoadVars = new LoadVars();
send_lv.fname = fname.text;
send_lv.lname = lname.text;
send_lv.email = email.text;
send_lv.dept = dept.text;
send_lv.campus = campus.text;
send_lv.uaid = uaid.text;
send_lv.phone = phone.text;
send_lv.send("http://distance.uaf.edu/ferpa/process.php", "POST");
gotoAndStop("certificate");
submit_button.addEventListener("click", submitListener);create a 2nd lv instance, use the sendAndLoad() method applied to send_lv and use your 2nd lv instance as the sendAndLoad() 2nd parameter:
var receiveLV:LoadVars=new LoadVars()
send_lv.sendAndLoad("xxxx.php",receiveLV,"POST");
p.s. if you want to parse the return from your php script, use the onLoad() or onData() methods applied to receiveLV. -
PHP scripts are not working after deploying it on website
Hi,
I have recently deployed my flex application on a web hosting (000webhost.com) and now my application is getting launched properly. Visit (www.kpratik.webatu.com).
I have used PHP script to interact with database MySQL. Locally everything was working fine but when I have deployed it to internet my PHP scripts are not working and any database opeartion is not getting performed. I have already chaned to host, username password in the PHP file as given my service provider.
Please let me know if you have any input on this.
Reponse will be highly appreciated.
Regards,
PratikHello,
Ok let me explain you where exactly it is going wrong.
I am constructing SQL query in my ActionScript code and I am passing this query to my PHP script using HTTPService. Now when I am hardcoing the query in PHP script i found it is working perfectly which means my query is not getting passed to PHP script.
Please let me know what could be the reason.
I am using POST method for HTTPService.
Thanks,
Pratik -
Help: Sending HTTPService request using POST to a php script
Hello all,
I need help in learning the proper method of communicating to php scripts from flex 3. I am very new to flex 3, php and web development. Thanks!
What I am trying to do is as follows:
1. User drags and drops a few items in a list control
2. user clicks a button to send these keywords to server php script
3. server will form a query based on the words sent and retrieve records and send them back
Here is what I have done so far:
1. When I send a request to server without any parameters, I amable to receive the request and query the database and send results in xml format
current issues I am facing:
1. I am gathering the list of entries in list control as follows:
<*** this function is callled when user decides to send request to server ***>private function startsearch():void {
var i:int;
var myAC:ArrayCollection = ArrayCollection(SelCtypes_id.dataProvider);
var nct:XML = new XML("<contenttypes></contenttypes>");
// add contenttype child now
for (i = 0; i<myAC.length; i++) {
nct.appendChild(XML(<contenttype>{myAC[i].toString()}</contenttype>));
var params:Object = new Object();
params.contenttypes = nct.toXMLString();
getsearchresults.send(params);
<*** my http service entry****>
<mx:HTTPService id="getsearchresults"
method="post"
url="http://localhost/search_xml.php"
result="handlesearchresultsXml(event)"
contentType="application/xml" />
This is what I see in flex debugger just when the request is sent out:
-> just before gersearchresults.send(params) call:
params.contenttypes = "<contenttypes>
<contenttype>AVI</contenttype>
<contenttype>SWF</contenttype>
</contenttypes>"
<*** within the HTTPrequest send function, I see th following in debugger ***>
message.contentType="application/xml"
message.body = paramsToSend shows "<contenttypes><contenttypes>
<contenttype>AVI</contenttype>
<contenttype>SWF</contenttype>
</contenttypes></contenttypes>"
This looks like my XML object is again formatted by an out <contenttypes> tag and the string is converted to be HTML safe (i.e. <, > notation).
It looks like I am not doing something right with my params formation to XML and HTTPservice is reformatting it to be some form of XML (I do not know XML well either :-)
My questions:
1. What am I doing wrong?
2. If there is a good example where I can send multiple parameters from flex client to php server and get data back where the request parameters will beof the form...
<query>
<type1>
<type1val>value1</type1val>
<type1val>value2</type1val>
</type1>
<type2>
<type2val>value3</type2val>
<type2val>value4</type2val>
</type2>
</query>
Thanks for your help!Hi, I'm having a problem with a similiar issue :/
I'm getting the error #1010 (A term is undefined and has no properties):
at flexGraph/httpResultHandlerUserInfo()
at flexGraph/__userInfoXML_result()
etc.
I removed some parts of the code so it's easier to read, if you can help me. I'm trying to populate a datagrid with info from a database, according to the alias I choose in the ComboBox. I get the error when I pick an alias from the ComboBox.
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.events.DropdownEvent;
[Bindable] private var usersInfo:ArrayCollection;
private function httpResultHandlerUserInfo(event:ResultEvent):void{
usersInfo = event.result.users.user;
private function chooseUserCB(event:DropdownEvent):void{
userInfoXML.send();
]]>
<mx:HTTPService id="userInfoXML" url="http://www.mysecondplace.org/flex/userInfo.php"
result="httpResultHandlerUserInfo(event)"
useProxy="false" method="POST">
<mx:request xmlns=""><alias>{usersAliasCB.selectedItem.alias}</alias></mx:request>
</mx:HTTPService>
<mx:ComboBox id="usersAliasCB"
x="10" y="10"
labelField="alias"
close="chooseUserCB(event)"/>
<mx:DataGrid id="testing"
x="10" y="100"
dataProvider="{usersInfo}"/>
Here's an example from the PHP file:
$query_user = "SELECT * FROM users WHERE alias='.$_POST["alias"].'";
Help me please -
How to send file as a parameter to php script
Hi,
Can any body help me to send the file as a parameter to php script. I am using the HttpURLConnection method.
ThankString msg= "name=" + strName + "&surname=" + strSurname;
byte[] msgAsBytes = msg.getBytes();
I am able to pass the string to the php script as
URLConnection con = url.openConnection();
((HttpURLConnection) con).setRequestMethod("POST");
con.setDoOutput(true);
con.setDoInput(true);
con.setUseCaches(false);
OutputStream oStream = con.getOutputStream();
oStream.write(msgAsBytes);
oStream.flush();and in php, i store into the global variable and it work fine
if(isset($_POST['name' ]&&isset($_POST[' surname'])it works fine for me. But problem is with the file. How can I send the file to php. Please help me. Thanks -
Send PDF form to e-mail as attachment with a PHP script on the server
Hi,
For several days I've been searching though the internet looking for a solution, a quite simple one in my opinion, but I got a little desperate not getting any result I want.
Okay. The Situation.
I have a PDF form to order sandwiches and drinks.
The PDF has serveral area's and columns where customers fill in the amount of the products they would like to order.
At a position of a field, the kitchen can almost blindly see what products a customer ordered.
Therefore, when someone fills in the form, I want to send the filled PDF by e-mail to the kitchen's e-mail adress. And important: the PDF in the kitchen's mailbox should be completely identical to the form the customer filled in.
So, I have an Order button in my form. I set the action as 'Submit a form'.
In the settings under 'Enter a URL for this link' I used just some PHP mailer script I also use on my website contact form.
IF I check 'HTML' under 'Export Format' the PHP mailer works fine. I receive an HTML e-mail listed the ordered products.
BUT
I do want the original filled PDF in my mailbox instead of an HTML e-mail.
So, for 'Export Format' I checked 'PDF The Complete Document'.
But then my PHP mailer script doesn't work anymore.
It gives errors like 'no valid e-mail adres' , etcetera etcetera.
Who has a solution?
Who has a working standard PHP script for me what just sends the kitchen an empty mail with the original PDF as attachment?!
There is no need to use any database or other more complex functionality. Just mail the filled PDF.You can submit whole PDF format as long as you enable usage rights on the PDF.
Normally Adobe Reader users can only submit the data, XFDF, FDF, XDP, XML.
To enable usage rights on the PDF you will need to use Adobe Acrobat Std/Pro.
As for the PHP Script; it depends on your PHP web server capabilities.
The script will be slightly different, if the server uses PHP Mail or PHP PEAR.
Just attach the submission to an email and send.
If the client is submitting the form from a standalone pdf reader app, you can also respond with a success or failure FDF \status message; otherwise, you can redirect to a success / failure URL.
For more information and online examples:
http://www.pdfemail.net/examples/ -
Can you create a form not using a php script?
I need to create a contact us form on my website using DW and have researched how and understand the easiest way is using a php script. Unfortuntately, my webhost server does not support this and will charge me an arm and a leg in order to to do it. Is there another way to have a functioning contact form not using a php script?
Yes and no.
You could use a mailto link for your form action instead of a PHP script.
There are several problems with this method though. First, when you do that, you are at the mercy of the viewer's computer set-up. Mailto links use whatever email client is installed on the machine in order to send the message. Public computers (libraries, colleges, etc) almost never have an email client installed, so when a viewer on one of those machines clicks the link, nothing happens. Secondly, your email address is open for spam harvesters, so you may end up with enlargement and nigerian scam emails flooding your inbox.
Since your provider doesn't give you a way to do it the right way on your server, you may want to look into email form services online and see if they are less expensive than your current alternative. -
We are attempting to use the PHP scripts (version 1.1) designed by Aaron Axelsen of University of Wisconsin - Whitewater (http://omega1.uww.edu/itunesu) to help facilitate authentication to iTunes U. We're bouncing credentials off our AD via PHP and LDAP, and once the user is authenticated, we're attempting to authorize them with the appropriate level of permission to iTunes U. To start off we're keeping it really simple. We have three levels: admin, instructor, and student. The administrative login works, but when we attempt to authorize a student or instructor, it appears to work but then brings the student to a blank iTune Store page. It does not recognize the identity string. Here's the debug output:
Analysis
+The destination string is valid and the corresponding destination item was found.+
+The identity string is valid and provides the following information:+
+Display Name Training Test01+
+Email Address [email protected]+
+Username testt+
+User Identifier userid+
+The credential string is valid but contains no known credentials.+
+The credential string contains the following credential which is not used within iTunes U:+
+1. Student@urn:mace:itunesu.com:sites:centenarycollege.edu:uniquename_fromitunes+
At the end of the Student credential string there it says "uniquename_fromitunes" - what is suppose to be there and where/how do I obtain that data string?
I have emailed the developer of these scripts and am awaiting his reply, but was hoping someone here might be able to help. Any help would be extremely appreciated. I'm befuddled at the moment and suspect the answer is a simple one.
Regards,
JohnIt's been a while since I mucked around with credentials, and I'm doing this via Perl rather than PHP, but the principle is the same. To give students site-level browse capability within iTunes U, I've created a credential called "Student@urn:mace:lafayette.edu" and given it download rights within iTunes. When I connect a student to iTunes U, they're given that credential by default. I have similar credentials for Faculty and College (college being everyone who isn't a student or faculty member).
If memory serves, iTunes U should automatically assign someone the "authenticated" role when they connect via your connection script, so if you setup content to be downloadable by "authenticated", then that should allow your students (and anyone else who properly authenticates) into the site. That allows for a quick and dirty separation of public vs. college content without mucking around with specific faculty/student/staff roles. If you want to go further, and restrict access to specific sections our courses, then you'll definitely want those sorts of focused roles, and make use of the ${IDENTIFIER} technique described in the access control documentation.
Ken Newquist
Lafayette College -
Developers Toolbox: MX Send Email php script generator
Hi,
I read Foundation PHP for Dreamweaver 8 (I have CS4
Dreamweaver but it’s still a good book).
In it, the author claims, that InterAKT has a product called
“MX Send Email” in the MX Kollection 3 suite of
Dreamweaver extensions, which automates the process of writing the
php script to process and send web email form data from forms
created in Dreamweaver, to the mail server. I went to their site
and it re directs to Adobe, and Adobe claims that they acquired
InterAKT a few years ago and included the above product in the
Developers Toolbox.
I downloaded the developers toolbox yesterday and for the
life of me I can’t figure out where I could find it or how it
works, it's very frustrating. Which makes me wonder if I should
plunk down an extra 300 bucks for the developers toolbox,
documentation is spotty at best – I can’t find any
books or discussion forums on the developers toolbox on how to use
this feature in the dev toolbox. No one seems to know anything
about it on the Extensions forum. Can someone give me some info
about this?
It seems to me there should be a simple way to generate some
PHP script for feedback forms created in Dreamweaver, especially
with the Developers toolkit.My other alternative is to buy a third
party extension to generate the scripts for 30 bucks, but if the
toolkit has it somewhere, where is the documentation or tutorial on
the adobe web site (which I dug for almost all day yesterday?
The Dev Toolkit has an option to insert a Captcha image so I
assume it's possible to do that too...
Or, Are there any on line tutorials which instruct on how to
create an email "Contact Us" form with Dreamweaver 4, which
includes info on writing the php script to process form data and
send it to mail server? If so can anyone direct me to it? Adobe has
one for Dreamweaver CS 3 on their site - but even that section of
the adobe site is not updated for CS4 and the tutorial even claims
that the Developers toolbox is not yet compatible with DW CS4 yet,
which contradicts the system requirements for the Dev Toolbox when
one downloads it.Mr. Powers,
Thanks for the info! BTW I really enjoyed reading your book a
few years ago, it really helped me to learn Dreamweaver back then.
I’m quite rusty now and trying to get back up to speed after
not using it for a few years. Sorry to hear about the ADDT thingy.
Thanks for the thread DWFAQ.info, I bookmarked the threads
and will read them over the weekend. Thanks for the Dreamweaver
Developer Toolbox link too! I had no idea that there was a Dev
toolbox forum I was looking for it on the adobe site for two days,
now I just noticed it has been included on the main index page, I
don’t think it was posted there yesterday but maybe I missed
it.
Does anyone know if there are any books possibly in the works
or being planned for the toolbox?
Also I’m kind of curious now, are the mixed feelings
about the toolbox because it (appears but I’m no expert), to
be a bit less user friendly for the average web designer? Either
that or just not enough documentation yet?
I had never heard about the toolbox until I bought my CS4
suite a few weeks ago. From above -
quote:
"what has now become Adobe Dreamweaver Developer Toolbox"
- what
was the toolbox? Is the toolbox the former InterAKT suite or
extensions? Or was it a mix of theirs and/or other extension
authors stuff? Did adobe buy up a few companies and add their own
stuff to it and market it as the toolbox?
When was the toolbox first released? Recently? Did Adobe
create it out of the merger with InterAkt? I’ve been out of
the web design loop for a few years, just trying to catch up on
what’s been going on lately. -
How to send php email using email from recordset?
Hi
I know the headers to use for php mail(), and I use it for
the contact form for my viewers in order to contact the directory
listing's email address ( of which I have hidden by using the words
'Email Us' and use the id to carry through to the form).
I have sucessfully used the $to = [email protected] but when I
want to use the $row_?['email'] it will not send.
Any suggestions? I use a recordset to retrieve the id of the
listing to the contact form.
I will want to follow the same procedure for my jobseekers to
contact employers job adverts.
Thanks
TheresaHi,
There are many sms gateways that have their own api to send sms. You can use them for sms. (They will charge you for the sms!!!)
Moderator edit: Link removed
Thanks
Edited by: PhHein on 20.10.2010 16:11 -
Uploading a file using a php script while running application with LCDS
Hi! I developping an application under Flex 2 / Java -
running on LCDS / JRun server.
I'm trying to add uploading capabilities. I'm using a php
script for the upload part.
First, I just try to put script on the app directory. Doesn't
work.
After that I set up an apache server from where I put a small
web site with my script. It's telling me that my file is
succesfully uploaded, but I can't find the file. The apache log
give me no error.
Someone can help me?Originally, I had problems w/ the file being placed in
C:/whatever.ext b/c I wasn't using relative paths.
This is the code I use:
$MAXIMUM_FILESIZE = 1024 * 1024 * 2; // 2MB
$newFileLoc = "./wherever/file.jpg"
if ($_FILES['Filedata']['size'] <= $MAXIMUM_FILESIZE) {
move_uploaded_file($_FILES['Filedata']['tmp_name'],
"./temporary/".$_FILES['Filedata']['name']);
rename( "./temporary/".$_FILES['Filedata']['name'],
$newFileLoc );
chmod( $newFileLoc, 0777 );
Modified from this article by Adobe:
http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=Live Docs_Book_Parts&file=17_Networking_and_communications_173_6.html
Maybe you are looking for
-
How to create a new admin for new hard drive/OS
I just got a new OS and Hard drive and repair shop that fixed said they would have skipped over anything asking to create password. When I turn on computer it loads fine and when I go to system pref/users it asks me for a old password. Nothing seems
-
Are ntfs files compatable with mac os lion
are ntfs files compatable with mac os lion
-
Get various error messages when trying to get messages or sending messages. RETR command did not succeed, get double, triple of same message, smtp is not connecting , have to exit, log back in several times before it will start downloading and then o
-
After upgrading to Firefox 8 (final build), some new issues happen ''intermittently'', some of them: 1. Missing bookmarks in Bookmark menu and the Bookmark button (opening Bookmark Manager shows everything still exist there). 2. Missing Auto Complete
-
Ichat, 10.4.3 and imac G5
Using an iMac G5, I am not able to get any audio or video conf with Macs or PCs . I always get "not enough bandwith" (with a 20 Mb line down and 2 up ! ) or "contact do not respond". For my friends using G4 macs it seems to work. Is it an G5 issue on