Not able to insert data into remote mySQL Database using PHP - windows-phone-7

I am trying to insert data into remote MySQL database using WP7 app but values does not get inserted, PHP file works perfect as my queries are getting inserted into DB using JAVA(Android). As I am new to C# I am facing this challenge.
The code goes like this:-
public MainPage()
{
InitializeComponent();
textBox1.Text = "http://www.abc.com/xyz/user_master.php?Email=abc#xyz.com&Username=abc&Password=xyzz&Phone=98989";
client = new WebClient();
client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
textBlock2.Text = e.Result;
}
}
private void button1_Click(object sender, RoutedEventArgs e)
{
client.DownloadStringAsync(new Uri(textBox1.Text));
}
Please correct me.

The problem is that you are using "DownloadStringAsync" which sends a GET and so you POST variable is not filled in PHP, you have to use "UploadStringAsync".
For now I can not tell you how the body has to look like... Until now I have used JSON all the time. Would be nice if you could post it here to let me know when you got it ;)
update
Ah, to slow =(
Could you please still post how your message body looks like!

Related

WebClient.DownloadProgressChanged not working?

I am using Windows Phone to download a file with a WebClient. The DownloadProgressChanged event does not work. It fires only once, returning a value of "4923206" for DownloadProgressChangedEventArgs.BytesRecieved. My code is:
private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
WebClient wb = new WebClient();
wb.DownloadProgressChanged += wbchange;
wb.OpenReadAsync(new Uri("http://sohowww.nascom.nasa.gov/data/LATEST/current_eit_304small.gif"));
}
private void wbchange(object sender, DownloadProgressChangedEventArgs e)
{
MessageBox.Show(e.BytesReceived.ToString()); (obviously in the end I will not be showing a message at every change)
}
What is wrong with this?
It's working absolutely fine, it just happens to have downloaded all the bytes on the first DownloadProgressChanged invoke.
If you read the documentation you'll see that this is the expected behaviour.

Get response from web browser for windows phone 'mango'

I m my application I want to use Webbrowser which will be using Wifi,after the Webbrower opens the the link (task.URL) ,I want to check what is the response like whether the linked got opened or it failed.How do I do that means get the response ?
WebBrowserTask task = new WebBrowserTask();
task.URL = "https://www.goggle.com/";
task.Show();
kindly help
Thanks.
Usually, to catch this use NavigationFailed event as follow:
void WebPage_Loaded(object sender, RoutedEventArgs e)
{
this.webHome.Navigate(new Uri(www,UriKind.Absolute));
this.webHome.NavigationFailed += webHome_NavigationFailed;
}
void webHome_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e)
{
this.webHome.NavigateToString("No web page available.");
}

Accessing a website using C#

I'm trying to make an App for windows phone 7. This app will basiclly retrive information from a website that we use at work as our working schedule then rearrange the retrived info into a metro style UI. To be honest i don't know where to start ie. how to retrive the info. Should i use webclient class? httpwebrequest class? or something else?
All idea are appriciated
Here is a:-
Update:-
Okay either im totally stupid or there is something wrong with the code i'm writing, that i can't figure it out. I was using the same code that you wrote BUT i still get an error that a definition for Proxy is not in the System.Net.WebRequest :( This is my code (the working version):-
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
if (!App.ViewModel.IsDataLoaded)
{
App.ViewModel.LoadData();
}
string url = "https://medinet.se/*****/schema/ibsef";
WebRequest request = WebRequest.Create(url);
request.BeginGetResponse(new AsyncCallback(ReadWebRequestCallBack), request);
}
private void ReadWebRequestCallBack(IAsyncResult callbackResult)
{
try
{
WebRequest myRequest = (WebRequest)callbackResult.AsyncState;
WebResponse myResponse = (WebResponse)myRequest.EndGetResponse(callbackResult);
using (StreamReader httpwebStreamReader = new StreamReader(myResponse.GetResponseStream()))
{
string results = httpwebStreamReader.ReadToEnd();
Dispatcher.BeginInvoke(() => parsertextBlock.Text = results);
}
myResponse.Close();
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
Dispatcher.BeginInvoke(() => parsertextBlock.Text = ex.ToString());
}
}
But if i add request.Proxy=null!! i get an error, that there is no definition for Proxy in (System.Net.WebRequest). And to be honest i start getting mad of this.
Yours
/Omar
The process is called ScreenScrape and i recommend you to use Html Agility Pack http://htmlagilitypack.codeplex.com/ . Make a web service that retrieves the information from your website and rearranges to appropriate format. Use your web service by a phone and display your data.
Use WebRequest ( http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx) and WebResponse ( http://msdn.microsoft.com/en-us/library/system.net.webresponse(v=vs.100).aspx) .
TIP: Set the WebRequest.Proxy property ( http://msdn.microsoft.com/en-us/library/system.net.webrequest.proxy.aspx) to null, as i find it will be much faster.
UPDATE: More info on WebRequest Proxy property
Set Proxy = null on the WebRequest object to avoid an initial delay (that way the request won't start auto detecting proxies, which i find it's faster).
WebRequest req = WebRequest.Create("yourURL");
req.Proxy = null;
It's in the System.Net namespace so put an using statement using System.Net; or
System.Net.WebRequest req = WebRequest.Create("yourURL");
req.Proxy = null;
Regards.

Logging errors when sending ASync email with MvcMailer

I'm using the excellent MvcMailer package to send email from within my application.
I'm using the SendAsync() method to send email, and would like to log errors + dispose of attachments i.e.
MailMessage message = UserMailer.SendSomeEmail(emailViewModel);
var client = new SmtpClientWrapper();
client.SendCompleted += (sender, e) =>
{
if (e.Error != null || e.Cancelled)
{
Logger.LogError(e.Error);
}
if (message != null)
{
message.Attachments.Dispose();
message.Dispose();
}
client.Dispose();
};
message.SendAsync("this means nothing afaik", client);
This works great, but it would get too painful to repeat the same snippet all over wherver I need to send email.
How should I set this up so that I can log any errors + dispose of message attachments when the async call is completed? There has to be a better way!
If what you're trying to do is to avoid having to write that logging and cleanup code every time you send an async email, the answer is simple -- stop using anonymous methods. Just take your current code and put it in a regular method like this:
public void AsyncSendCompleted(object sender, EventArgs e)
{
// Use an appropriate type instead of EventArgs so you can get
// stuff like e.Cancelled and e.Error
// The rest of your code goes here
}
Now use this method as the event handler for your SendCompleted event:
client.SendCompleted += AsyncSendCompleted;

Passing (Asp.Net) Session variable (uploaded by uploadify) from webmethod to same page?

When i try to get uploaded filename from generic handler (upload.ashx) using session its ok, no problem. I can also use webmethod on samepage and uploadify works great, but Session["fileName"] is getting null. Is there anything wrong on my code? Do i only need to use generic handler to get filename?
[WebMethod(EnableSession = true)]
public void LoadPicture(HttpContext context)
{
try
{
HttpPostedFile file = context.Request.Files["Filedata"];
context.Session["fileName"] = file.FileName;
....................Some resize and save image codes.........
context.Response.Write("1");
}
catch (Exception ex)
{
context.Response.Write("0");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
using (_modelService = new ModelService())
{
ModelEntity _models = new ModelEntity();
......some codes....
_models.modelphoto = Session["fileName"].ToString();
_modelService.ModelAdd(_models);
}
}
Uploadify uses Flash. Flash doesn't send cookies. In ASP.NET sessions are tracked by cookies. So, no session with uploadify, sorry.

Resources